小程序之组件传参

父向子组件传参

父组件传递

user(e) {
      let id = e.currentTarget.dataset.id;
      let detail = e.currentTarget.dataset.detail;
      wx.navigateTo({
        url: '/pages/member/package-payment-code/package-payment-code?id=' + id + '&detail=' + detail
      })
    },

子组件接受

  onLoad: function(options) {
    if (options.type == 1) {
      wx.setNavigationBarTitle({
        title: "套餐付款码"
      })
      this.setData({
        boln: true
      })
    } else {
      wx.setNavigationBarTitle({
        title: "券付款码"
      })
      this.setData({
        boln: false,
        detail: options.detail
      })
    }
    if (options.id) {
      this.setData({
        id: options.id
      })
    }
  },

子向父组件及祖组件传参

//子组件
	let author = "true"
    that.triggerEvent("traCheckedNum", author)
//父组件
<dialogBar wx:if="{{meal.IsUse && meal.IsIncrease}}" meal="{{meal}}" type='0' bind:traCheckedNum="traCheckedNum" skinStyle="{{skinStyle}}">

// 子组件传值
    traCheckedNum: function (e) {
      console.log(e.detail)
      this.triggerEvent('myevent', e)
    },
//父组件的父级
<setMeal meal="{{item}}" skinStyle="{{skinStyle}}" bind:myevent='getMask' index="{{navIndex}}"/>

getMask(e) {
    console.log(e.detail.detail);
    if (e.detail.detail) {
      this.onShow();
    }
  },
发布了35 篇原创文章 · 获赞 47 · 访问量 8594

猜你喜欢

转载自blog.csdn.net/qq_40665861/article/details/103321475