attribute | type | default | required | Introductions |
Object | - | - | Initial data for the page | |
function | - | - | Lifecycle callbackMonitor page loading | |
function | - | - | Lifecycle callbackMonitor page display | |
function | - | - | Lifecycle callbackMonitor Page Initial Rendering Completed | |
function | - | - | Lifecycle callbackMonitor Page Hiding | |
function | - | - | Lifecycle callbackListen Page Uninstall | |
function | - | - | Listen for user drop-down actions | |
function | - | - | Handle function for bottoming event on page | |
function | - | - | User click on the upper right to forward | |
function | - | - | Handler for page scrolling trigger event | |
function | - | - | At present tab Page, click tab Time trigger | |
Other | any- | - | - | Other developers can add arbitrary functions or data to the Object parameter, which can be accessed in the page's function with this. This portion of the property is made a deep copy when the page instance is created. |
//index.jsPage({data: {text: "This is page data."},onLoad: function(options) {// Do some initialize when page load.},onShow: function() {// Do something when page show.},onReady: function() {// Do something when page ready.},onHide: function() {// Do something when page hide.},onUnload: function() {// Do something when page close.},onPullDownRefresh: function() {// Do something when pull down.},onReachBottom: function() {// Do something when page reach bottom.},onShareAppMessage: function () {// return custom share data when user share.},onPageScroll: function() {// Do something when page scroll},onResize: function() {// Do something when page resize},onTabItemTap(item) {console.log(item.index)console.log(item.pagePath)console.log(item.text)},// Event handler.viewTap: function() {this.setData({text: 'Set some data for updating view.'}, function() {// this is setData callback})},customData: {hi: 'MINA'}})
data
is used in the first rendering of the pageInitial data。data
Will be JSON
The string form is passed from the logical layer to the render layer, so data
in must be converted toJSONType: string, number, boolean, object, array.<view>{{text}}</view><view>{{array[0].msg}}</view>
Page({data: {text: 'init data',array: [{msg: '1'}, {msg: '2'}]}})
Name | type | Introductions |
query | Object | Open parameters in the current page path |
attribute | type | Introductions |
scrollTop | Number | Distance a page has been scrolled vertically (in px) |
parameter | type | Introductions |
from | String | Forward the source of the event. button:: In-page forward on menu:: Retweet menu on top right |
target | Object | if from The value is buttonThen target That triggered this retweet. button, otherwise undefined |
WebViewUrl | String | |
string | Where users click to share |
fields | type | description | default |
title | string | Forwarding Title | Current mini program name |
path | string | Forwarding Path | Current page path, must be a full path starting with /. |
imageUrl | string | Custom image url, can be a local file url, a package file url or a network image url. Support PNG and JPG, display image aspect ratio is 5:4 | Use default screenshot |
entryDataHash | string | Listen to the user clicking the in-page forward button, only with this parameter, fast sharing will be supported | - |
string | Specify the type of share | "miniapp" |
Value | Description |
0 | Share to QQ friends |
1 | Share to QQ space |
2 | Open from current chat window, quickly share to current chat window |
3 | Share to WeChat friends |
4 | Share to WeChat Friends |
5 | Share panel to recent contacts |
6 | Share to Quick Share Friends List |
Value | Description |
"miniapp" | Shared as a mini program, the title, path, imageUrl, entryDataHash parameters take effect |
"picture" | Shared as a picture, imageUrl, entryDataHash parameters will take effect |
Page({onShareAppMessage(res) {if (res.from === 'button') {// From the in-page forwarding buttonconsole.log(res.target)}return {title: 'Custom Forwarding Title',path: '/page/user?id=123'}}})
app.json
or in the Page Configuration;parameter | type | Introductions |
index | String | Number of tabItem clicked, starting with 0 |
pagePath | String | Page path of tabItem clicked |
text | String | Click tabItem on text |
Page({onTabItemTap(item) {console.log(item.index)console.log(item.pagePath)console.log(item.text)}})
<view bindtap="viewTap"> click me </view>
Page({viewTap: function() {console.log('view tap')}})
Page({viewTap: function() {console.log('view tap')}})
field | type | Required | describe |
data | Object | yes | The data to be changed this time |
callback | Function | no | Interface update caused by setData after rendering |
<!--index.wxml--><view>{{text}}</view><button bindtap="changeText"> Change normal data </button><view>{{num}}</view><button bindtap="changeNum"> Change normal num </button><view>{{array[0].text}}</view><button bindtap="changeItemInArray"> Change Array data </button><view>{{object.text}}</view><button bindtap="changeItemInObject"> Change Object data </button><view>{{newField.text}}</view><button bindtap="addNewField"> Add new data </button>
// index.jsPage({data: {text: 'init data',num: 0,array: [{text: 'init data'}],object: {text: 'init data'}},changeText: function() {// this.data.text = 'changed data' // Don't change this.data directly.// You should use setDatathis.setData({text: 'changed data'})},changeNum: function() {// Alternatively, you can modify this.data and then immediately set the modified field with setData.this.data.num = 1this.setData({num: this.data.num})},changeItemInArray: function() {// For object or array fields, you can modify a subfield directly under it, which is usually better than modifying the whole object or array.this.setData({'array[0].text':'changed data'})},changeItemInObject: function(){this.setData({'object.text': 'changed data'});},addNewField: function() {this.setData({'newField.text': 'new data'})}})
getCurrentPages()
when App.onLaunch
is running, the page has not been generated yet.
Was this page helpful?