微信小程序获取子组件数据中的data值和方法

子组件:

  data: {
    show: true,
  },

   checkFun() {
      this.show = false
    }

父组件:

父组件使用子组件:
<child id="child"></child>

// 获取子组件中的data值
const child= this.selectComponent('#child');
console.log(child.data.show);

// 调用子组件的方法
 useChildFun() {
    this.selectComponent('#child').checkFun();
 }

评论

暂无评论