查看“小程序页面参数的传递与获取”的源代码
←
小程序页面参数的传递与获取
跳转至:
导航
,
搜索
因为以下原因,您没有权限编辑本页:
您所请求的操作仅限于该用户组的用户使用:
用户
您可以查看与复制此页面的源代码。
==通过函数传参== ===列表页=== ====WXML==== index.wxml: <nowiki> <view wx:for="{{postList}}"> <view data-id="{{item.id}}" bind:tap="onGoToDetail" class="post-container">点击详情</view> </view></nowiki> ====JS==== <nowiki> onGoToDetail(event){ //console.log(event)//打印事件 console.log(event.currentTarget.dataset.id) const pid = event.currentTarget.dataset.id wx.navigateTo({ url:'/pages/post-detail/index?pid='+pid }) },</nowiki> ===详情页=== ====WXML==== <nowiki> <text>我是详情页</text></nowiki> ===JS=== <nowiki> onLoad: function (options) { console.log(options) }, </nowiki> ====输出==== 在列表页上点击链接, 会跳转到详情页 [[文件:wexin22051401.png|600px]] <nowiki> {pid: "1"] </nowiki> ==通过组件传参== ===列表页=== <nowiki> <navigator url="/pages/post-detail/index?pid=1" hover-class="navigator-hover">点击详情</navigator></nowiki> ===详情页=== ====JS==== <nowiki> // pages/post-detail/index.js import {postList} from '../../data/data.js' // console.log(postList) Page({ /** * 页面的初始数据 */ data: { }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { console.log(options) console.log(options.pid) const postData = postList[options.pid] console.log(postData) this.setData({ postData }) }, </nowiki>
返回至
小程序页面参数的传递与获取
。
导航菜单
个人工具
登录
命名空间
页面
讨论
变种
视图
阅读
查看源代码
查看历史
更多
搜索
导航
首页
最近更改
随机页面
帮助
工具
链入页面
相关更改
特殊页面
页面信息