<p>先看下面这组代码</p>
<!--父组件-->
<father>
<!--子组件-->
<son @hand="hand"></son>
</father>
hand(){
// #ifndef MP-WEIXIN
console.log(this) //father
// #endif
// #ifdef Mp-WEIXIN
console.log(this) //son
console.log(this.$root) //father
// #endif
}
通过以上代码应该是可以看出一些端倪
总结:
页面组件里面引入子组件
子组件初始化会执行一个回调,这个回调里面的 this 在 h5 和app 指向这个页面组件
也就是说可以访问 this.data
但是编译到微信小程序里面,这个 this 指向这个子组件,访问不了 this.data 所以必须 this.$root.data