当前位置:网站首页>小程序页面导航
小程序页面导航
2022-07-16 17:50:00 【new Promise】
小程序中实现页面导航的两种方式
- 声明式导航
- 在页面上声明一个导航组件
- 通过点击组件实现页面跳转
- 编程式导航
- 调用小程序的导航API,实现页面的跳转
一、声明式导航
1.导航到tabBar页面
tabBar页面指的是被配置为tabBar的页面
在使用组件跳转到指定的tabBar页面时,需要指定url属性和open-type属性,其中:
- url表示要跳转到的页面地址,必须以/开头
- open-type表示跳转的方式,必须为switchTab
<navigator url="/pages/message/message" open-type="switchTap">导航到消息页面</navigator>
2.导航到非tabBar页面
非tabBar页面:没有在tabBar配置的页面
在使用组件跳转到普通的非tabBar页面时,则需要指定url属性和open-type属性:
- url表示要跳转到的页面地址,必须以/开头
- open-type表示跳转的方式,必须为navigate
<navigator url="/pages/info/info" open-type="navigate">导航到非tabBar页面</navigator>在导航到非tabBar页面时,open-type=“navigate” 可以省略不写,也可以导航到指定页面
3.后退导航
如果要后退到上一页面或多级页面,则需要指定open-type属性和delta属性,:
- open-type的值必须是navigateBack,表示要进行后退导航
- delta的值必须是数字,表示要后退的层级
<navigator open-type="navigateBack" delta="1">后退至上一页</navigator>注:如果只是后退到上一页,则delta可以省略不写,因为值默认是1
二、编程式导航
1. 导航到tabBar页面
调用wx.switchTab(object,object)方法,可以跳转到tabBar页面,其中object参数对象的属性如下:
示例代码:
<button bindTab="goMessage">跳转到message</button> goMessage(){ wx.switchTab({ url:"/pages/message/message" }) }
2. 跳转到非tabBar页面
调用wx.switchTo(object,object) 方法,可以跳转到非tabBar页面。其中object参数对象的属性列表:
示例代码:
<button bindtap="goInfo">跳转非tabBar页</button> goInfo(){ wx.navigateTo({ url:'/pages/info/info' }) },
3. 后退导航
调用wx.navigateback(object,object)方法,可以返回上一页面或多级页面;其中object参数队形的属性列表如下:
示例代码:
<button bindtab="goBack">返回上一页</button> goBack(){ wx.navigateBack({ delta:1 // 默认是1,可以省略不写 }); },
边栏推荐
- 2022.7.4-7.10 AI industry weekly (issue 105): snails
- 2022 Hangzhou future science and technology city digital economy talent Programming Competition
- Tiktok protocol interface, protocol analysis add_ x_ bogus add_ signature
- 21、当在浏览器中输入了URL之后,程序是怎样执行的?
- 最近有点忙。
- Why should V-for add key
- 接口测试—校验参数合法性/容错性测试
- 支付流程面试思路
- 从 0 到 1 搭建企业级数据治理体系!
- OpenGL ES学习(2)——顶点着色器和片元着色器
猜你喜欢

OpenGL es learning (5) - Lighting

【学浪下载教程】01学浪下载之Fiddler的配置

【uniapp-checkbox】修改uniapp-checkbox复选框的样式

淘特商品详情API接口(商品销量接口,商品价格排序接口,回头客常买接口,APP商品详情接口,商品属性接口)

A down jacket live broadcast Gmv soared by 430%. Is this the secret of off-season hot sales?

OpenGL es learning (6) -- recognizing textures
![[uniapp calls wechat Payment] uniapp development applet - call wechat payment](/img/a1/52e3acf6448c509d34ae135bae1402.png)
[uniapp calls wechat Payment] uniapp development applet - call wechat payment

OpenGL ES学习(4)——投影和绘制

wallys/QCA9880/ WiFi 5 (802.11ac) mini PCIe cards deliver higher Tx power and performance (Sponsored

还在用 System.currentTimeMillis() 统计代码耗时?太 Low 了!
随机推荐
【学浪下载教程】06学浪模拟网页版登录,无需客户端和全局代理软件
Economic dispatching of power system (complete code implementation in Matlab)
自定义类型详解(c语言)
Dynamic memory management (C language)
学生管理系统(简易低配版)
最近发现了动画库 lottie
1. Self made script language - Chapter 1 Notes
【学浪下载教程】01学浪下载之Fiddler的配置
[word] the inserted formula is grayed out, and the failure is solved
【ui-app移动端UI框架】
Single source shortest path
feign调用传递请求头
How to create Dutch auction smart contract
【uniapp调用微信支付】uniapp开发小程序-调用微信支付
全网首发 nuScenes数据集网盘 + 下载方法
[Xuelang download tutorial] 03 proxifier settings for Xuelang Download
graph theory
Nc20566 [scoi2010] games
软件测试 - 用例篇
Processing numbers are expressed in Chinese


