在compoent中,当调用$emit('callback', params)
完成时,我需要返回的值。有人可以帮忙吗?
vueComponent:
methods: {
test: function () {
if(this.$emit('cb', param1) === true){
// this not working
console.log('return true')
}else{
console.log('return false')
}
}
}
vueRoot:
methods: {
cb: function () {
return true;
}
}
答案 0 :(得分:2)
根据我在原始问题下面的评论,$emit
只告诉父组件发生了一个事件,并允许它做一些事情以响应事件和随之发送的任何数据。子组件无法知道父操作的结果是什么。为了在回调结束后告诉子组件某些内容,您需要通过prop
发送该值,并让子watch
对支柱的值进行任何更改。