微信小程序传递参数(字符串、数组、对象)

来源:互联网 发布:威海模具编程招聘 编辑:程序博客网 时间:2024/06/04 19:14

(转载)http://blog.csdn.net/yanxiaosa/article/details/73643066

作者:燕潇洒

导读:微信小程序向下个页面传递各种参数,和下个页面对参数的获取。

传递字符串

    //传递参数(?model中,model是下个页面获取时的key)   click:function(e){    var model = this.data.str;    wx.navigateTo({      url: '../detail/detail?model=' + model,    })  }  //在下个页面的onload中获取,  onLoad: function (options) {    var bean = options.model;    console.log(options.model)    this.setData({        model:bean    })  },
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

传递对象

//通过提供的JSON.stingify方法,将对象转换成字符串后传递  click:function(e){    var model = JSON.stringify(e.currentTarget.dataset.model);    wx.navigateTo({      url: '../detail/detail?model=' + model,    })  }//接收onLoad: function (options) {    //将字符串转换成对象    var bean = JSON.parse(options.model);    if(options.model == null){      wx.showToast({        title: '数据为空',      })      return;    }      this.setData({          model:bean      })      },
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21

传递数组

    方式和传递对象相同,注意类型即可!

阅读全文
0 0
原创粉丝点击