小程序父級更新組件值

開始:

父級: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
      })
    }
}

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章