小程序官网关于Navigator介绍:
![](https://img.haomeiwen.com/i1764965/13ad3118fd9f161a.png)
open-type = navigate
对应 wx.navigateTo的功能
open-type = redirect
对应 wx.redirectTo的功能
open-type = switchTab
对应 wx.switchTab的功能
open-type = reLaunch
对应 wx.reLaunch的功能
[1.1.0](https://mp.weixin.qq.com/debug/wxadoc/dev/framework/compatibility.html)
navigateBack
对应 wx.navigateBack的功能
页面跳转时传递
主页面:
<!-- sample.wxml -->
<view class="btn-area">
<navigator url="/page/navigate/navigate?title=newPagePath" hover-class="navigator-hover">跳转到新页面</navigator>
<navigator url="../../redirect/redirect/redirect?title=重定向页面&ohterParmas=123" open-type="redirect" hover-class="other-navigator-hover">在当前页打开</navigator>
<navigator url="/page/index/index" open-type="switchTab" hover-class="other-navigator-hover">切换 Tab</navigator>
</view>
这里是带参跳转的,一个参数就用?=title,如果多个参数就是用?=title=”“&ohterParmas=”“。
页面跳转后,onload接受参数
Page({
data:{
//不需要再写user_id。
},
onLoad(options) {
console.log('onLoad')
console.log(options.user_id)
if (options.user_id) {
this.setData({
user_id: options.user_id
})
} else {
this.setData({
user_id: '暂无'
})
}
}
网友评论