Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does WeChat Mini Programs register the page?

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the relevant knowledge of "how to register WeChat Mini Programs page". In the operation of the actual case, many people will encounter such a dilemma. Then let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

After registering for Mini Program, follow the registration page.

Code description

/ / index.js

/ / obtain an application instance

Var app = getApp ()

Page ({

Data: {

Motto: 'Hello World'

UserInfo: {}

}

/ / event handling function

BindViewTap: function () {

Wx.navigateTo ({

Url:'.. / logs/logs'

})

}

OnLoad: function () {

Console.log ('onLoad')

Var that = this

/ / call the method of the application instance to obtain global data

App.getUserInfo (function (userInfo) {

/ / Update data

That.setData ({

UserInfo:userInfo

})

})

}

})

Page function

The Page () function takes an object parameter that is used to register a page. It can specify the initial data of the page, life cycle functions, event handling functions, and so on.

Initialization data

The data specified by the data property is used when the page is first drawn. Two pieces of data are defined in this example: motto and userinfo.

Event handling

The bindViewTap function is bound to the user information representation container in index.wxml. This function is called every time the user clicks on the container. Its content is very simple, is to migrate to the log screen.

Life cycle function

In this example, the onLoad function is registered, which is called automatically when the page loads.

The onLoad function calls the app.getUserInfo function with the function object as an argument. This function object takes userinfo as an argument, and the function is to set userinfo to the userinfo object of the page data.

JavaScript knowledge

An anonymous function object is passed in the call to app.getUserInfo. There are at least two things about this object that C programmers are not used to.

This and that

The code first defines a that variable and assigns this to it, and then calls the setData function using that. This is done because the this pointer to javascript points to the context in which the function is called. This function is called in app.getUserInfo, so instead of using this directly, you can only use the that that is prepared in advance and points to the object on this page.

Function object

In app.js, the function object cb passed to getUserInfo as an argument is called as follows:

Typeof cb = = "function" & & cb (this.globalData.userInfo)

We can divide the expression into two parts with the & & symbol. On the left, get the type of cb to confirm whether it is "function". If so, continue to execute the right half, calling the cb function with this.globalData.userInfo as the argument; if the type of cb is not "function", the cb function will not be called because the expression is already false.

To put it another way, it actually means:

If (typeof cb = = "function")

{

Cb (this.globalData.userInfo)

}

This is the content of "how to register WeChat Mini Programs page". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report