这里的setTimeout()会发生this指代问题
settiemout(function(){
//这里this指向window
//使用箭头函数直接指向上层this
eventHub.$emit('post-deleted', this.post)
},2000)
按照教程,直接使用function()回调函数,发生this指代错误,一直监听不到发送过来的post,调试发现是要用箭头函数,使this直接指向上级作用域
//延时2秒返回上一页
setTimeout(()=>{
console.log(this.post)
eventHub.$emit('post-deleted', this.post)
//返回上一页
wx.navigateBack({
delta: 1 //返回的页面数,如果 delta 大于现有页面数,则返回到首页,
});
},2000)
推荐文章: