当前位置:网站首页>【微信小程序】页面导航
【微信小程序】页面导航
2022-07-25 23:18:00 【热爱编程的小白白】
目录
小程序 - 视图与逻辑
页面导航
1. 什么是页面导航
2. 小程序中实现页面导航的两种方式
页面导航 - 声明式导航
1. 导航到 tabBar 页面
- url 表示要跳转的页面的地址,必须以 / 开头
- open-type 表示跳转的方式,必须为 switchTab
<navigator url="/pages/message/message" open-type="switchTab">导航到消息页面</navigator>2. 导航到非 tabBar 页面
- url 表示要跳转的页面的地址,必须以 / 开头
- open-type 表示跳转的方式,必须为 navigate
<navigator url="/pages/info/info" open-type="navigate">导航到info页面</navigator>注意:为了简便,在导航到非 tabBar 页面时,open-type="navigate" 属性可以省略。
3. 后退导航
- open-type 的值必须是 navigateBack,表示要进行后退导航
- delta 的值必须是数字,表示要后退的层级
<navigator open-type="navigateBack">后退</navigator>注意:为了简便,如果只是后退到上一页面,则可以省略 delta 属性,因为其默认值就是 1。
页面导航 - 编程式导航
1. 导航到 tabBar 页面
| 属性 | 类型 | 是否必选 | 说明 |
| url | string | 是 | 需要跳转的 tabBar 页面的路径,路径后不能带参数 |
| success | function | 否 | 接口调用成功的回调函数 |
| fail | function | 否 | 接口调用失败的回调函数 |
| complete | function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) |
<button bindtap="gotoMessage">跳转到message页面</button> gotoMessage() {
wx.switchTab({
url: '/pages/message/message'
})
},
2. 导航到非 tabBar 页面
| 属性 | 类型 | 是否必选 | 说明 |
| url | string | 是 | 需要跳转的 tabBar 页面的路径,路径后不能带参数 |
| success | function | 否 | 接口调用成功的回调函数 |
| fail | function | 否 | 接口调用失败的回调函数 |
| complete | function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) |
<button bindtap="gotoInfo">跳转到info页面</button> gotoInfo() {
wx.navigateTo({
url: '/pages/info/info'
})
},3. 后退导航
| 属性 | 类型 | 默认值 | 是否必选 | 说明 |
| delta | number | 1 | 否 | 返回的页面数,如果 delta 大于现有页面数,则返回到首页 |
| success | function | 否 | 接口调用成功的回调函数 | |
| fail | function | 否 | 接口调用失败的回调函数 | |
| complete | function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) |
<button bindtap="goBack">后退</button> goBack() {
wx.navigateBack({
delta: 1
})
},边栏推荐
猜你喜欢

Classes and objects (3)

How does Navicat modify the language (Chinese or English)?

驱动板网线直连电脑共享网络配置
![[interface performance optimization] reasons for index failure and how to optimize SQL](/img/b9/64058c823c4497ac36bfb62a101816.jpg)
[interface performance optimization] reasons for index failure and how to optimize SQL

Data broker understanding

Several commonly used traversal methods

idea设置get、set模板解决boolean类型字段的命名问题

Single model common sense reasoning first surpasses human beings! HFL summit openbookqa challenge

File contains vulnerability

Enterprise level inventory management system of code audit
随机推荐
HJ7 取近似值
Unity uses macros
Implementation of date class
Rental experience post
Drive board network cable directly connected to computer shared network configuration
Ma Tiji Wanmin hall Chef
@Autowired annotation required attribute
Details of notification (status bar notification)
Mongodb的特点、与MySQL的差别、以及应用场景
File contains vulnerability
Data broker understanding
Very simple vsplayaudio online music player plug-in
Discuz atmosphere game style template / imitation lol hero League game DZ game template GBK
赋能合作伙伴,亚马逊云科技如何落地“扶上马,送一程”?
[QNX Hypervisor 2.2用户手册]9.7 generate
网格参数化Least Squares Conformal Maps实现(3D网格映射到2D平面)
Redis expiration key deletion strategy [easy to understand]
Basic knowledge of radar
Yii2 behavior usage and its calling method
Apple CMS V10 template /mxone Pro adaptive film and television website template