您的位置:宽带测速网 > 网络知识 > 小程序如何实现页面之间的传参

小程序如何实现页面之间的传参

2025-06-17 10:01来源:互联网 [ ]

1.使用url带参数传递数据

代码实现:

toSomeone:function(event){

wx.navigateTo({

url:'some/some?id='+event.target.id,

})

}

获取传递来的数据

onLoad:function(options){

console.log(options)

},

2.使用组件模板 template传递参数

<templateis="good"data="{{data}}"></template>

3.使用缓存传递参数

//缓存数据

wx.setStorage({

key:'userInfo',

data:res.userInfo

})

getUsersInfo:function(){

//读取缓存登录

wx.getStorage({

key:'userInfo',

success:function(res){

this.userInfo=res.userInfo;

}

})

}