手抄报 安全手抄报 手抄报内容 手抄报图片 英语手抄报 清明节手抄报 节约用水手抄报

微信小程序页面传递循环列表数据

时间:2024-10-13 09:42:35

1、打开开发者工具,在项目pages文件夹下,新建目录,在目录内新建mypage,并在app.json中将mypage设为第一页面

微信小程序页面传递循环列表数据

2、在mypage.wxml中写代码如下:<view wx:for="辘腋粪梯{{datary}}" data-index="{撑俯擂摔{index}}" data-cont="{{item}}" class="item {{curItem==index?'focus':''}}" catchtap="itemtap">{{index}}-{{item}}</view>

微信小程序页面传递循环列表数据

3、在mypage.wxss中写代码如下:.item{width: 100rpx;height: 100rpx;margin: 20rpx;background-color: rebeccapurple}.focus{background-color: red;}

微信小程序页面传递循环列表数据

4、在mypage.js中添加数据如下:data: { datary:['hello','world'], curItem:0},

微信小程序页面传递循环列表数据

5、在mypage.js中为点击事件添加响应函数,代码如下:itemtap:funct坡纠课柩ion(e){ console.l泠贾高框og(e) var that = this; that.setData({curItem:e.target.dataset.index}) wx.navigateTo({ url: '../logs/logs?item='+e.target.dataset.cont, })}

微信小程序页面传递循环列表数据

6、在logs.wxml中添加代码如下:<view>{{datavar}}</view>

微信小程序页面传递循环列表数据

7、在logs.js中添加数据接收传递过来的参数,在onload事件中显示数据,代码如下:Page({data: { logs: [], datavar:null,},onLoad: function (options) { console.log(options) this.setData({ datavar:options.item })}})

微信小程序页面传递循环列表数据

8、点击编译,运行代码,在左侧模拟器,点击列表项,会跳转到logs页面,并成功传递了参数

微信小程序页面传递循环列表数据
© 手抄报圈