微信小程序頁面傳遞參數的示例:
示例1:
在對應的wxml文件中添加以下代碼:
<block wx:for="{{postList}}" wx:for-item="item" wx:for-index="idx">
<view catchtap="onPostTap" data-postid="{{item.postId}}">
<template is="postItem" data="{{...item}}"/>
</view>
</block>
在對應的js文件中添加以下代碼:
onPostTap: function (event){
var postId = event.currentTarget.dataset.postid;
wx.navigateTo({
url: "post-detail/post-detail?id=" + postId;
})
}
示例2:
A頁面代碼:
//需要傳遞的參數名為postId
wx.navigateTo({
url: "post-detail/post-detail?id=" + postId
})
B頁面代碼:
//另一頁面接收參數
onLoad: function (option) {
var postId = option.id;
}