Analysis of onLoad in WeChat Mini Program

不言
Release: 2018-06-23 15:00:51
Original
4812 people have browsed it

This article mainly introduces the detailed explanation and simple examples of onLoad in WeChat Mini Program. Friends in need can refer to

OnLoad in WeChat Mini Program

onLoad is a life cycle function, indicating page loading

onLoad has an Object type parameter by default, which refers to the query parameter called by other pages to open the current page

Give me an example~

When we have a click method onTap in the js script of the first page

When the page is clicked, the page jumps to the second page, use? The form of id = secondId passes a value to the second page (secondId here is a value that has already been obtained)

onTap: function(){ 
 wx.navigateTo({ 
  url: "second?id=" + secondId 
 })
Copy after login

Then we go to second Receive this id in the js file

The parameter option here is the Object parameter we received before, so we can use this id value in second.js

Page({ 
 onLoad: function(options){ 
  var secondId = options.id; 
   console.log(postId); 
 } 
})
Copy after login

Note:

When I first started running this code, the postId output was always undefined, and the output There is no id value in option. Finally, the solution was solved by changing the url in first from single quotes to double quotes. I thought it was really the reason, but I changed it back to single quotes and found that it still runs normally. I don't know where the bug is, but I have encountered this situation several times where I have to change something insignificant to make it run normally.

The above is the entire content of this article. I hope it will be helpful to everyone's study. For more related content, please pay attention to the PHP Chinese website!

Related recommendations:

WeChat Mini Program Example of scroll-view implementing pull-up loading and pull-down refresh

WeChat applet implements the method of dynamically setting placeholder prompt text and button selection/cancellation state

The above is the detailed content of Analysis of onLoad in WeChat Mini Program. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template