我有一个包含模态组件的组件:
UserComponent:
我发送了一个ID:
`<a href="#" class="text-primary" data-toggle="modal" >
<i @click.prevent="item(tag.id)"class="fa fa-fw fa-eye fa-2x"></i>
</a>`
您收到的功能:
`item: function(id){this.$store.dispatch('getViewProfile',id);},`
我的vuex模块:
`export default {
state: {
item:[],},mutations: {
LOAD_PROFILE(state,data){
state.itemProfile = data;
},}
actions:{
getViewProfile: function(context,id){
let that = this;
let url = '/user/'+id;
axios.get(url).then(response => {
context.commit('LOAD_PROFILE',{
'user': response.data,});
}).catch(function (response) {
console.log(response)
});
}`
我在模态组件中使用bootstrapVue库:
`<b-modal ref="view-profile-modal" hide-footer title="Using Component Methods">
Hello World
</b-modal>`
功能:
`computed:{
user: function () {
if(typeof this.$store.state.users.itemProfile.user !== 'undefined') {
return this.$store.state.users.itemProfile.user;
}
},}`
我收到的信息很好,我无法获得的是模态已执行,因为它告诉我无法找到show()
`this.$refs['view-profile-modal'].show()`
但是如果我在主要组件中运行模态,它将起作用! 这个菜鸟的一些帮助:3 P / d:我正在将组件加载到laravel的app.js中