WeChat applet page jump and data transfer
This article mainly introduces relevant information on WeChat applet page jumps and detailed examples of data transfer. Here are example codes to help you learn and understand at home. Friends in need can refer to
WeChat Mini program page jump and data transfer
1. Pilot
In Android, our Activity and Fragment both have the concept of stack in them. WeChat Mini The program page also has the concept of stack in it. There are four ways to jump to the WeChat applet page:
1.wx.navigateTo(OBJECT);
2.wx.redirectTo(OBJECT);
3.wx.switchTab( OBJECT);
4.wx.navigateBack(OBJECT)
5. Use to implement the corresponding jump function;
Analysis:
where navigateTo is Save the original page in the page stack. When jumping to the next page, the target page is also pushed into the stack. Only in this case can you click the return button on the phone to jump to the previous page;
RedirectTo and switchTab both clear the original page in the stack first, and then push the target page into the stack. Using these two jump methods, you cannot return to the previous page through the system's return key, but exit directly. Mini program;
When using redirectTo, it must be used with the tabBar or the jump button in the page, otherwise you cannot return to the previous page;
-
The page that switchTab jumps to must be the page declared in tabBar;
The fields defined in tabBar cannot exceed 5 pages, and the page stack level of the applet cannot exceed 5 layers. .
navigateBack can only return to the specified page in the page stack, and is generally used in conjunction with navigateTo.
wx.navigateTo and wx.redirectTo are not allowed to jump to the tabbar page, only wx.switchTab can be used to jump to the tabbar page
2. Specific operations for page jump
(1)wx.navigateTo(OBJECT)
Keep the current page and jump Go to a page in the application and use wx.navigateBack to return to the original page.
Parameters | Type | Required | Description |
---|---|---|---|
url | String | is the path of | to the non-tabBar page in the application that needs to be jumped. Parameters can be included after the path. Parameters and paths are separated by ?, parameter keys and parameter values are connected by =, and different parameters are separated by &; for example, 'path?key=value&key2=value2' |
success | Function | No | Callback function for successful interface call |
fail | Function | No | Callback function for interface call failure |
complete | Function | No | Callback function for end of interface call Function (executed successfully or failed) |
Sample code:
wx.navigateTo({ url: 'test?id=1'//实际路径要写全 })
##
//test.js Page({ onLoad: function(option){ console.log(option.query) } })
(2) wx.redirectTo(OBJECT)
Close the current page and jump to a page within the application.Type | Required | Description | |
---|---|---|---|
String | is the path of | to the non-tabBar page in the application that needs to be jumped. Parameters can be included after the path. Parameters and paths are separated by ?, parameter keys and parameter values are connected by =, and different parameters are separated by &; for example, 'path?key=value&key2=value2' | |
Function | No | Callback function for successful interface call | |
Function | No | Callback function for interface call failure | |
Function | No | Callback function for end of interface call Function (executed successfully or failed) |
wx.redirectTo({ url: 'test?id=1' })
##( 3) wx.switchTab(OBJECT)
Jump to the tabBar page and close all other non-tabBar pages
OBJECT parameter description:Required | Description | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
is the path of the tabBar page that | needs to be jumped (the page needs to be defined in the tabBar field of app.json). Parameters cannot be included after the path | success | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
No | Callback function for successful interface call | fail | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
No | Callback function for failed interface call | complete | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
No | The callback function at the end of the interface call (will be executed if the call is successful or failed) |
参数 | 类型 | 必填 | 说明 |
---|---|---|---|
delta | Number | 1 | 返回的页面数,如果 delta 大于现有页面数,则返回到首页。 |
示例代码:
// 注意:调用 navigateTo 跳转时,调用该方法的页面会被加入堆栈,而 redirectTo 方法则不会。见下方示例代码 // 此处是A页面 wx.navigateTo({ url: 'B?id=1' })
// 此处是B页面 wx.navigateTo({ url: 'C?id=1' })
// 在C页面内 navigateBack,将返回A页面 wx.navigateBack({ delta: 2 })
(5)使用
navigator
页面链接。
参数 | 类型 | 必填 | 说明 |
---|---|---|---|
url | String | 应用内的跳转链接 | |
redirect | Boolean | false | 打开方式为页面重定向,对应 wx.redirectTo(将被废弃,推荐使用 open-type) |
open-type | String | navigate | 可选值 ‘navigate'、'redirect'、'switchTab',对应于wx.navigateTo、wx.redirectTo、wx.switchTab的功能 |
hover-class | String | navigator-hover | 指定点击时的样式类,当hover-class=”none”时,没有点击态效果 |
hover-start-time | Number | 50 | 按住后多久出现点击态,单位毫秒 |
hover-stay-time | Number | 600 | 手指松开后点击态保留时间,单位毫秒 |
示例代码:
<navigator url="navigate?title=navigate" hover-class="navigator-hover">跳转到新页面</navigator> <navigator url="redirect?title=redirect" open-type="redirect" hover-class="other-navigator-hover">在当前页打开</navigator> <navigator url="index" open-type="switchTab" hover-class="other-navigator-hover">切换 Tab</navigator>
3.页面的路由和生命周期
(1)页面的路由
在小程序中所有页面的路由全部由框架进行管理,对于路由的触发方式以及页面生命周期函数如下:
路由方式 | 触发时机 | 路由后页面 | 路由前页面 |
---|---|---|---|
初始化 | 小程序打开的第一个页面 | onLoad,onShow | |
打开新页面 | 调用 API wx.navigateTo 或使用组件 | onLoad,onShow | onHide |
页面重定向 | 调用 API wx.redirectTo 或使用组件 | onLoad,onShow | onUnload |
页面返回 | 调用 API wx.navigateBack 或用户按左上角返回按钮 | onShow | onUnload(多层页面返回每个页面都会按顺序触发onUnload) |
Tab 切换 | 调用 API wx.switchTab 或使用组件 或用户切换 Tab | 各种情况请参考下表 |
Tab 切换对应的生命周期(以 A、B 页面为 Tabbar 页面,C 是从 A 页面打开的页面,D 页面是从 C 页面打开的页面为例):
当前页面 | 路由后页面 | 触发的生命周期(按顺序) |
---|---|---|
A | A | Nothing happend |
A | B | A.onHide(), B.onLoad(), B.onShow() |
A | B(再次打开) | A.onHide(), B.onShow() |
C | A | C.onUnload(), A.onShow() |
C | B | C.onUnload(), B.onLoad(), B.onShow() |
D | B | D.onUnload(), C.onUnload(), B.onLoad(), B.onShow() |
D(从分享进入) | A | D.onUnload(), A.onLoad(), A.onShow() |
D(从分享进入) | B | D.onUnload(), B.onLoad(), B.onShow() |
4.参数传递
(1)通过路径传递参数
通过路径传递参数在wx.navigateTo(OBJECT)、wx.redirectTo(OBJECT)和
示例代码:以wx.navigateTo为代表
" wx.navigateTo({ url: 'test?id=1'//实际路径要写全 })
//test.js Page({ onLoad: function(option){ console.log(option.id) } })
参数与路径之间使用?分隔,参数键与参数值用=相连,不同参数用&分隔;
test?id=1 中id为参数键,1 为参数值
在目的页面中onLoad()方法中option对象即为参数对象,可以通过参数键来取出参数值
以上就是本文的全部内容,希望对大家的学习有所帮助,更多相关内容请关注PHP中文网!
相关推荐:
The above is the detailed content of WeChat applet page jump and data transfer. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Detailed explanation of PHP page jump functions: Page jump techniques for header, location, redirect and other functions, which require specific code examples. Introduction: When developing a Web website or application, jumping between pages is an essential function. PHP provides a variety of ways to implement page jumps, including header functions, location functions, and jump functions provided by some third-party libraries, such as redirect. This article will introduce in detail how to use these functions

Xianyu's official WeChat mini program has quietly been launched. In the mini program, you can post private messages to communicate with buyers/sellers, view personal information and orders, search for items, etc. If you are curious about what the Xianyu WeChat mini program is called, take a look now. What is the name of the Xianyu WeChat applet? Answer: Xianyu, idle transactions, second-hand sales, valuations and recycling. 1. In the mini program, you can post idle messages, communicate with buyers/sellers via private messages, view personal information and orders, search for specified items, etc.; 2. On the mini program page, there are homepage, nearby, post idle, messages, and mine. 5 functions; 3. If you want to use it, you must activate WeChat payment before you can purchase it;

WeChat applet implements picture upload function With the development of mobile Internet, WeChat applet has become an indispensable part of people's lives. WeChat mini programs not only provide a wealth of application scenarios, but also support developer-defined functions, including image upload functions. This article will introduce how to implement the image upload function in the WeChat applet and provide specific code examples. 1. Preparatory work Before starting to write code, we need to download and install the WeChat developer tools and register as a WeChat developer. At the same time, you also need to understand WeChat

To implement the drop-down menu effect in WeChat Mini Programs, specific code examples are required. With the popularity of mobile Internet, WeChat Mini Programs have become an important part of Internet development, and more and more people have begun to pay attention to and use WeChat Mini Programs. The development of WeChat mini programs is simpler and faster than traditional APP development, but it also requires mastering certain development skills. In the development of WeChat mini programs, drop-down menus are a common UI component, achieving a better user experience. This article will introduce in detail how to implement the drop-down menu effect in the WeChat applet and provide practical

Implementing picture filter effects in WeChat mini programs With the popularity of social media applications, people are increasingly fond of applying filter effects to photos to enhance the artistic effect and attractiveness of the photos. Picture filter effects can also be implemented in WeChat mini programs, providing users with more interesting and creative photo editing functions. This article will introduce how to implement image filter effects in WeChat mini programs and provide specific code examples. First, we need to use the canvas component in the WeChat applet to load and edit images. The canvas component can be used on the page

Use the WeChat applet to achieve the carousel switching effect. The WeChat applet is a lightweight application that is simple and efficient to develop and use. In WeChat mini programs, it is a common requirement to achieve carousel switching effects. This article will introduce how to use the WeChat applet to achieve the carousel switching effect, and give specific code examples. First, add a carousel component to the page file of the WeChat applet. For example, you can use the <swiper> tag to achieve the switching effect of the carousel. In this component, you can pass b

To implement the picture rotation effect in WeChat Mini Program, specific code examples are required. WeChat Mini Program is a lightweight application that provides users with rich functions and a good user experience. In mini programs, developers can use various components and APIs to achieve various effects. Among them, the picture rotation effect is a common animation effect that can add interest and visual effects to the mini program. To achieve image rotation effects in WeChat mini programs, you need to use the animation API provided by the mini program. The following is a specific code example that shows how to

Implementing the sliding delete function in WeChat mini programs requires specific code examples. With the popularity of WeChat mini programs, developers often encounter problems in implementing some common functions during the development process. Among them, the sliding delete function is a common and commonly used functional requirement. This article will introduce in detail how to implement the sliding delete function in the WeChat applet and give specific code examples. 1. Requirements analysis In the WeChat mini program, the implementation of the sliding deletion function involves the following points: List display: To display a list that can be slid and deleted, each list item needs to include
