Home >WeChat Applet >Mini Program Development >Analysis of onLoad in WeChat Mini Program
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 })
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); } })
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
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!