从subnvue页面传值:
close(){
const popup_comment = uni.getSubNVueById('popup_comment')
popup_comment.hide()
uni.$emit('close_comment',{
content_index: this.content_index
})
console.log('我发送了一个事件')
}
在vue页面接收:
uni.$on('close_comment',function(data){
console.log('监听到了') //可以打印
this.content_index = data.content_index
console.log(this.content_index) //可以打印
this.get_comment_list(this.content_index); //报错
})
报错如下:
[Vue warn]: Error in event handler for "close_comment": "TypeError: this.get_comment_list is not a function"
13:29:46.205 (found <Root>)
13:29:46.227 TypeError: this.get_comment_list is not a function
难道uni.$on中只可以接收传值,不可以调用其它函数吗???
需求:希望子窗体关闭后,在vue页面能执行一次函数,以刷新数据。子窗体是一个评论框,关闭后需要更新总评论条数
2 个回复
初学者123 (作者) - 80后IT男
这个问题解决了。无论是从vue向subnvue传值,还是从subnvue向vue传值,都需要使用: let vm = this这样的语句,不然页面不刷新,也不会执行其中的函数
k***@sina.cn
这样也不行啊。不要用function回调才行。
初学者123 (作者)
不能用 this, 要用 vm.参考我的另一篇文章:
https://ask.dcloud.net.cn/article/37700?notification_id-817621__item_id-36214
2020-10-27 14:52
8***@qq.com
回复 初学者123: 这个uni.$on用箭头函数不就行了吗
2022-04-13 15:04