search
HomeWeChat AppletMini Program DevelopmentIntroduction to WeChat Mini Program Development Registration Page

This article mainly introduces the relevant information of the WeChat Mini ProgramRegistration Page. Friends who need it can refer to

WeChat Mini Program——Page

Page()Function is used to register a page. Accepts an object parameter, which specifies the initial data of the page, life cycle function, event handling function, etc.

object parameter description:

TypeDescriptiondataObjectInitial data of the pageFunctionLife cycle function--listen to page loadingonReady FunctionLife cycle function--listen for page rendering completiononShowFunctionLife cycle function--listen for page display onHideFunctionLife cycle function--listening page hideFunctionLife cycle function--listen for page unloadingOthersAny Developers can add any function or data to the Object parameter, which can be accessed using this

Sample code:

//index.js
Page({
 data: {
 text: "This is page data."
 },
 onLoad: function(options) {
 // Do some initialize when page load.
 },
 onReady: function() {
 // Do something when page ready.
 },
 onShow: function() {
 // Do something when page show.
 },
 onHide: function() {
 // Do something when page hide.
 },
 onUnload: function() {
 // Do something when page close.
 },
 // Event handler.
 viewTap: function() {
 this.setData({
  text: 'Set some data for updating view.'
 })
 }
})

Initialization data

Initialization data will be used as the first rendering of the page. The data will be transmitted from the logic layer to the rendering layer in the form of JSON, so the data must be in a format that can be converted into JSON: String, numbers, Boolean values, Object , Array.

The rendering layer can bind data through WXML.

Sample code:

<view>{{text}}</view>
<view>{{array[0].msg}}</view>
Page({
 data: {
 text: &#39;init data&#39;,
 array: [{msg: &#39;1&#39;}, {msg: &#39;2&#39;}]
 }
})

Event handling function

In addition to initialization data and life cycle functions, Page can also define some special Function: event handling function. In the rendering layer, event binding can be added to the component. When the trigger event is reached, the event processing function defined in the Page will be executed.

Sample code:

click me

Page({
 viewTap: function() {
 console.log(&#39;view tap&#39;)
 }
})

Page. prototype.setData()

The setData function is used to send data from the logic layer to the view layer, while changing the corresponding value of this.data.

Note:

Directly modifying this.data is invalid and cannot change the status of the page. It will also causing data inconsistency.
The data set at a time cannot exceed 1024kB. Please try to avoid setting too much data at one time.

setData() parameter format

Accepts an object and represents the value corresponding to the key in this.data in the form of key,value Change to value.
The key can be very flexible and given in the form of a data path, such as array[2].message, a.b.c.d, and does not need to be predefined in this.data.

Sample code:

<!--index.wxml-->
<view>{{text}}</view>
<button bindtap="changeText"> Change normal data </button>
<view>{{array[0].text}}</view>
<button bindtap="changeItemInArray"> Change Array data </button>
<view>{{obj.text}}</view>
<button bindtap="changeItemInObject"> Change Object data </button>
<view>{{newField.text}}</view>
<button bindtap="addNewField"> Add new data </button>
//index.js
Page({
 data: {
 text: &#39;init data&#39;,
 array: [{text: &#39;init data&#39;}],
 object: {
  text: &#39;init data&#39;
 }
 },
 changeText: function() {
 // this.data.text = &#39;changed data&#39; // bad, it can not work
 this.setData({
  text: &#39;changed data&#39;
 })
 },
 changeItemInArray: function() {
 // you can use this way to modify a danamic data path
 var changedData = {}
 var index = 0
 changedData[&#39;array[&#39; + index + &#39;].text&#39;] = &#39;changed data&#39;
 this.setData(changedData)
 },
 changeItemInObject: function(){
 this.setData({
  &#39;object.text&#39;: &#39;changed data&#39;
 });
 },
 addNewField: function() {
 this.setData({
  &#39;newField.text&#39;: &#39;new data&#39;
 })
 }
})

You don’t need to understand the following right away, but it will help later.

Life cycle function

The following figure illustrates the life cycle of a Page instance.

Introduction to WeChat Mini Program Development Registration Page

The routes of the page

The routes of all pages in the mini program are all Framework For management, the triggering method of routing and the page life cycle function are as follows:

##Attribute
onLoad
onUnload
##Routing methodTrigger timingPage after routingPage before routingInitializationThe first page opened by the applet onLoad, onShowOpen a new pageCall onLoad, onShowonHidePage redirectionCall API wx.redirectTo or use Component onLoad, onShowonUnloadPage returnCall API wx.navigateBack or user Press the return button in the upper left corneronShowonUnloadTab switchingUsers switch Tabs in multi-Tab modeOpen onLoad for the first time, onshow; otherwise onShowonHide##Thank you for reading, I hope it can help everyone, thank you for your support of this site !
API wx.navigateTo or use the component

The above is the detailed content of Introduction to WeChat Mini Program Development Registration Page. 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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft