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页面,并成功传递了参数