小程序带参跳转、Page与Component传值

带参跳转

wx.navigateTo({
    url: '/pages/hope/hope?isHope=' + 0, 
})

跳转的页面有一个参数初始化isHope : 1

Page传值Component

Component中定义show属性

  properties: {
    show: {
      type: "Boolean",
      value: Boolean,
      observer: function (news, olds, path) {

      }
    }
  }

Page中wxml中该Component(joinHope-cmp)绑定

  
  

通过改变Page中showJoinHope的值传递给Component的show

    this.setData({
      showJoinHope: true,
    })

Component传值Page

Component中已wishSuccess名字,e是传递的参数

        var e = {
          success: true
        }
        this.triggerEvent('wishSuccess', e, '');

Page的wxml给组件绑定bind:wishSuccess="onWishSuccess"

  
  

并实现onWishSuccess方法,从event取参

  onWishSuccess: function (event){
    
  }

你可能感兴趣的:(小程序带参跳转、Page与Component传值)