微信小程序页面之间的传值

微信小程序还是基于html和js来做,因此页面之间的传值,和网页中的url之间的跳转很相似,将参数拼接在url中(请注意如果数据量大的话,通过url拼接参数会传递不完整,可以采用全局变量来做,或者使用微信小程序的本地存储功能)

举个例子:从页面1跳转到页面2

页面1

 wx.navigateTo({url: '../scanResult/scanResult?ppid=' + ppid + '&result=' + scanUrl,})

页面2

/**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this//不要漏了这句,很重要
    var ppid = options.ppid  //接收刚才传过来的值
    var result = options.result //接收刚才传过来的值
    that.setData({
      ppid: ppid,
      scanResult: result
    })
}

猜你喜欢

转载自blog.csdn.net/helang296479893/article/details/81303433