欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

微信小程序页面传多个参数跳转页面的实现方法

程序员文章站 2023-08-16 09:17:37
这里举例跳转两个参数 传递多少个也可以 这里传参数 我写作 data-item data-id 来绑定 同事加了点击事件bindtap 在index.js 在...

这里举例跳转两个参数 传递多少个也可以

微信小程序页面传多个参数跳转页面的实现方法

这里传参数 我写作 data-item data-id 来绑定 同事加了点击事件bindtap

在index.js

微信小程序页面传多个参数跳转页面的实现方法

在 data 里我写的是假数据

在跳转页面的函数里传e 后面定义的东西根据e来确定 可以在console打印

console.log(e)

微信小程序页面传多个参数跳转页面的实现方法

这样我们就拿到了 传递的数据 然后进行定义等

微信小程序页面传多个参数跳转页面的实现方法

这里跳转详情页的函数 wx.navigateto 这是一种跳转的方法 tabbar页面要用wx.switchtab 路径后面加上 jsonstr 等

在跳转的详情页面的onload方法里面写

微信小程序页面传多个参数跳转页面的实现方法

我们打印上个页面传入的数据

微信小程序页面传多个参数跳转页面的实现方法

打印出上个页面传入的数据 在进行that.setdata 就行了

wxml:

<view class='fast-container'>
 <block wx:for="{{fast}}" wx:key="fast">
  <view class='fast-row' bindtap='goindexdetail' data-item="{{item}}" data-id="{{list}}">
    <view class='row-tou'>
      <image class='img' src='{{item.image}}'></image>
    </view>
    <view class='row-content'>
     <view class='text'>{{item.name}}</view>
     <view class='content'>{{item.summary}}</view>
    </view>
  </view>
 </block>
</view>

index.js

page({
 /**
  * 页面的初始数据
  */
 data: {
  fast:[ //假数据
   { 'name': 'red', 'image': '/img/123.jpg','summary':'我是红色'},
   { 'name': 'green', 'image': '/img/123.jpg', 'summary': '我是绿色' },
   { 'name': 'blue', 'image': '/img/123.jpg', 'summary': '我是蓝色' },
   { 'name': 'orange', 'image': '/img/123.jpg', 'summary': '我是橘色' }
  ],
  list:[ //假数据
   {'content':'content-red'},
   { 'content': 'content-green' },
   { 'content': 'content-blue' },
   { 'content': 'content-orange' }   
  ]
 },
 // ----跳转详情页
 goindexdetail : function (e) {
  // console.log('我要传入的值e+++',e)
  let id = e.currenttarget.dataset.id;
  let item = e.currenttarget.dataset.item;
  console.log('我传入的data-id+',id,'我传入的data-item=',item)
  let str = json.stringify(id);
  let _str = json.stringify(item)
  wx.navigateto({
   url: '/pages/index/indexdetail/indexdetail?jsonstr=' + str + "&strr=" + _str,
  })
 },
 /**
  * 生命周期函数--监听页面加载
  */
 onload: function (options) {
 },
 /**
  * 生命周期函数--监听页面初次渲染完成
  */
 onready: function () {
 },
 /**
  * 生命周期函数--监听页面显示
  */
 onshow: function () {
 },
 /**
  * 生命周期函数--监听页面隐藏
  */
 onhide: function () {
 },
 /**
  * 生命周期函数--监听页面卸载
  */
 onunload: function () {
 },
 /**
  * 页面相关事件处理函数--监听用户下拉动作
  */
 onpulldownrefresh: function () {
 },
 /**
  * 页面上拉触底事件的处理函数
  */
 onreachbottom: function () {
 },
 /**
  * 用户点击右上角分享
  */
 onshareappmessage: function () {
 }
})

indexdetail.js

page({
 /**
  * 页面的初始数据
  */
 data: {
  detail: [],
  detaillist,
 },
 /**
  * 生命周期函数--监听页面加载
  */
 onload: function (options) {
  let that = this
  // console.log(options)
  // console.log(options.jsonstr)
  // console.log(options.strr)
  let item = json.parse(options.jsonstr)
  let id = json.parse(options.strr)
  console.log('上个页面跳转的data-item++', item)
  console.log('上个页面跳转的data-id++', id)
  that.setdata({
   detail: id,
   detaillist: item
  })
 },
 /**
  * 生命周期函数--监听页面初次渲染完成
  */
 onready: function () {
 },
 /**
  * 生命周期函数--监听页面显示
  */
 onshow: function () {
 },
 /**
  * 生命周期函数--监听页面隐藏
  */
 onhide: function () {
 },
 /**
  * 生命周期函数--监听页面卸载
  */
 onunload: function () {
 },
 /**
  * 页面相关事件处理函数--监听用户下拉动作
  */
 onpulldownrefresh: function () {
 },
 /**
  * 页面上拉触底事件的处理函数
  */
 onreachbottom: function () {
 },
 /**
  * 用户点击右上角分享
  */
 onshareappmessage: function () {
 }
})

总结

以上所述是小编给大家介绍的微信小程序页面传多个参数跳转页面的实现方法,希望对大家有所帮助