小程序跳转页面并携带参数,有两种情况,一是在wxml里通过navigator url跳转,一种是在js里通过点击事件跳转,下面案例为跳转详情页面
在wxml中:
<view class='wait-solve' wx:for="{{items}}" wx:key="items.name" wx:for-index="idx" wx:for-item="item"><navigator url='../../details/details?name={{item.name}}' class="weui-cell weui-cell_access" hover-class="weui-cell_active"><view class="weui-cell__bd" data-name="{{item.name}}" bindtap='jumpDetails'>{{item.value}}</view><view class="weui-cell__ft weui-cell__ft_in-access"></view></navigator></view>
在js中:
jumpDetails:function(e){var name=e.currentTarget.dataset.name;console.log(name)wx.navigateTo({url: "../details/details?name=" + name,})},
在跳转到详情页时获取携带过来的值:在onLoad中获取
data: {title: "详情",name: "", //跳转携带过来的参数}, onLoad: function(options) {this.setData({name: options.name})//这个时候就拿到传过来的name了console.log(this.data.name)}