小程序跳转页面并携带参数,有两种情况,一是在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)
}
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/234254.html原文链接:https://javaforall.cn