我想从父组件的另一个组件中调用该方法...所以,假设我有notie.vue,并且有一个名为“ flash”的方法,当我获得成功时,我想在API请求之后调用它。
这么说吧:在获取API之后,我想使用参数---> notie.success('notification type','notification message')调用类似的内容
这是代码:
道具是这样定义的
props: {
type: {
default: 'info',
required: false
},
content: {
default: 'This is just demo text',
required: false
},
visible: {
type: Boolean,
default: false
}
}
这是数据
data: function () {
return {
show: true
}
}
这是方法
methods: {
flash: function () {
this.show = true;
}
}
这是HTML代码
<div class="notie" v-bind:class="[{active: show}, type]" v-on:click="close()">
<div class="notie__icon" :class="type"></div>
<div class="notie__content" v-text="content"></div>
</div>
例如,在这里我想调用我的notie组件
submit: function () {
this.$http.post('/api/books/add', {
data: this.data,
}).then(function (response) {
// I want to use notie component right here to notice to users.
}, function (response) {
});
}
所以我的问题是在API请求成功或错误后如何调用flash()?
最佳答案
如果您想称呼“父母”,请使用此this.$parent
如果您想调用儿童的方法,请使用此this.$children[0].someMethod()
这是一个数组this.$children
关于javascript - 来自另一个组件VueJS版本1的调用方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41608685/