微信小程序之传递数据(两种方法)

微信小程序之传递数据(两种方法)
①方法一:一看就懂
注意?为英文?

wx.navigateTo({
url: '../card/card?id=1',
})

接受方法:
在跳转到的页面js中

Page({ 
data:{
theId:null//设置为空,接受传来的数据
},
onLoad:function(options){
console.log(options)
this.setData({ theId:options.id})
}
})

在跳转到的页面的wxml中:

<view>  传过来的数据的id是:{{theId}}view>

②也是一看就懂

<navigator url="../card/card?id=11&username=哈哈哈">
<button bindtap='gotoCreatsth'>编辑button>
navigator>

接受方法:同上
在跳转到的页面js中

Page({ 
data:{
theId:null,//设置为空,接受传来的数据
theName:null
},


onLoad:function(options){
console.log(options)
this.setData({ theId:options.id,theName:options.username})
},

在跳转到的页面的wxml中:

<view>  传过来的数据的id是:{{theId}}+{{theName}}
view>

你可能感兴趣的:(微信小程序之传递数据(两种方法))