Home  >  Article  >  WeChat Applet  >  Mini program development--page value transfer

Mini program development--page value transfer

零下一度
零下一度Original
2017-05-22 12:02:261943browse

This article mainly introduces relevant information on the detailed explanation of value transfer on the WeChat mini program page. Friends who need it can refer to

Detailed explanation of value transfer on the WeChat mini program page

1. Pass values ​​across pages.

1. Use the navigator tag to pass values ​​or wx.navigator, such as


Here, pass the good_id=16 parameter into the detail page, and then accept it in the onload method of the detail page.


If you need to pass multiple parameters, use & link. But



If you want to transfer complex types such as arrays, dictionaries, etc., you must first use JSON.stringify() to convert Pass it as a string.


Note: If the converted string contains the symbol "?", only the string before "?" will be passed. I guess this problem may be that the routing processing inside the mini program is sensitive to this "?"

Okay, this is the first url that relies on jumping to pass values ​​with parameters

2. Use getCurrentPages(); to get all the pages in the stack, and then write the data to the corresponding page


You can pass strings here, you can also pass arrays, etc. ,


In this way, the address is passed and accepted

Note: This method is suitable for passing values ​​later (that is, already existing page), so that the data can be found in the stack and actively written, and it must be accepted in the onshow() method, because only the onshow() method will be executed when returning again.

3. Write locally, across pages After taking out wx.setStorage/wx.getStorage, etc., the applet encapsulates many methods for writing local data, each with its own emphasis, so I won’t go into details here



4. Declare the data as a global variable

var detail = getApp().detail; Can be obtained on any page

2. Passing values ​​within the page

1. Set the id method to identify the parameters passed after the jump


Obtained from the click method swiperTap defined by bindtap: function(e);, var id = e.currentTarget.id;

2. Method of setting data-xxx To identify the value to be passed


Note: {{index}} in data-index="{{index}}" is valid. When using wx-for to render the view layer, index represents the subscript of the click. It is obtained in the click method swiperTap: function(e); defined by bindtap, that is, var index = e.currentTarget.dataset.index; The same is true for other parameters. , var type = e.currentTarget.dataset.type;

3 . form form and input input box



##【Related recommendations】

1.

WeChat applet complete source code Download

2.

Takeaway: Implement similar anchor function

3.

WeChat alarm clock: Dialogue implementation

The above is the detailed content of Mini program development--page value transfer. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn