微信小程序页面点击按钮传值与取值

//小程序内使用event来传值只能在本页面,到别的页面接收的是空的,所以先传到js在通过url传值


A页面:WXML

<button bindtap="GoHome" open-type="launchApp"  data-index="123">进入餐厅</button>

A页面:js page内即可

GoHome: function (e) {
    wx.navigateTo({
    	url: "../HomePage/HomePage?UName=" + e.target.dataset.index,
	})
}


B页面:js data内先声明一个参数,用以接收值

data: {
    UName:''
},

onload内写,自动获取

onLoad: function (options) {
     this.setData({
     UName: options.UName
    })
    console.log(this.data.UName)
  },


你可能感兴趣的:(小程序)