小程序父级更新组件值

开始:

父级:index

<view class="index">
<footer phoneOptions='{{phoneOptions}}' downObj="{{downObj}}" hide="{{hideBjData}}"></footer>
</view>
onShareAppMessage: function (res) {
    if (res.from === 'button') {
      // 来自页面内转发按钮
    }
    this.setData({   //在转发时改变参数,然后组件执行 _onRefresh方法
      hideBjData: {
        'isshowBJ': false,
        'screeningNo': 2
      }
    })

    return {
      title: '您好,我是选址顾问' + this.data.cardData.name
    }
  },

组件:footer  这里只展示更改hide的值

properties: {
    hide:{
      type:Object,
      value: {},
      observer: '_onRefresh'    //此值改变的函数
    }
  },
methods: {
    _onRefresh(newVal, oldVal){  //这里只要父级值改变,就会执行
      const _this = this;
      this.setData({
        'isshowBJ': newVal.isshowBJ,
        'screeningNo': newVal.screeningNo
      })
    }
}
发布了149 篇原创文章 · 获赞 51 · 访问量 23万+

猜你喜欢

转载自blog.csdn.net/caoyan0829/article/details/94398714