In the ASCF framework, you can register a page using Page or register a page using Component.
Page(Object object)
Since: 1.0.0
Parameters
The input parameter is an object containing the following fields.
| Attribute | Type | Mandatory | Description |
|---|---|---|---|
| data | object | No | Initial data of the page. |
| options | object | No | Component options of the page, which are the same as those in Component. |
| onLoad | function | No | Lifecycle callback, used to listen for page loading. |
| onShow | function | No | Lifecycle callback, used to listen for page display. |
| onReady | function | No | Lifecycle callback, used to listen for initial rendering of the page. |
| onHide | function | No | Lifecycle callback, used to listen for page hiding. |
| onUnload | function | No | Lifecycle callback, used to listen for page unloading. |
| onPullDownRefresh | function | No | A function that listens for the pull-down action from a user. |
| onReachBottom | function | No | A function that processes the pull-up event on a page. |
| onPageScroll | function | No | A function that processes the scrolling event on a page. |
| onTabItemTap | function | No | A function triggered when a tab is tapped. |
| getTabBar | function | No | A function used to obtain the custom tabBar instance. Since: 1.0.10 |
| onShareAppMessage | function | No | A function triggered when a user taps the menu bar in the upper right corner. Since: 1.0.16 |
| Others | any | No | A parameter that adds any function or data to a parameter of the Object type and uses this to access the parameter. |
onLoad(Object query)
Called when a page is loaded. This function is called only once for one page. You can obtain the parameters of the loaded page's path from onLoad.
Since: 1.0.0
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| query | Object | No | Parameter obtained from the URL field of the has.navigateTo and has.redirectTo APIs, for example, path?key1=value1&key2=value2. The base library parses the string content into an Object. |
onPageScroll(Object object)
Called when a page is scrolled.
Since: 1.0.0
Parameters
The input parameter is an object containing the following fields.
| Attribute | Type | Mandatory | Description |
|---|---|---|---|
| scrollTop | Number | No | The vertical scrolling distance of the page, in px. |
onTabItemTap(Object item)
Called when a tab is tapped.
Since: 1.0.0
Parameters
The input parameter is an object containing the following fields.
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| index | String | No | Sequence number of the tapped tab item, starting from 0. |
| pagePath | String | No | Page path of the tapped tab item. |
| text | String | No | Button text of the tapped tab item. |
Example:
Page({
onTabItemTap(item) {
console.info(item.index);
console.info(item.pagePath);
console.info(item.text);
}
}); getTabBar()
Obtains the custom tabBar instance.
Since: 1.0.10
Example:
Page({
onShow() {
if (typeof this.getTabBar === 'function' && this.getTabBar()) {
this.getTabBar().setData({ selected: 1 });
}
}
}); // index.js
Page({
data: {
text: 'This is page data.'
},
onLoad: function(options) {
// Executed when a page is created.
},
onShow: function() {
// Executed when the page is displayed.
},
onReady: function() {
// Executed when the page is rendered for the first time.
},
onHide: function() {
// Executed when the page is hidden.
},
onUnload: function() {
// Executed when the page is unloaded.
},
onPullDownRefresh: function() {
// Executed upon a pull-down refresh.
},
onReachBottom: function() {
// Executed when the page reaches the bottom.
},
onPageScroll: function() {
// Executed when the page is scrolling.
},
onTabItemTap(item) {
// Executed when a tab is tapped.
},
// Event callback.
handleTap: function() {
this.setData(
{
text: 'new text'
},
function() {
// Triggered after setData is updated.
}
);
},
// Other custom data
extraData: {
hi: 'extra data'
}
}); Use Component() to construct pages. Various features of components are available, such as behaviors.
Custom methods and page lifecycles must be defined in methods.
Component({
data: {
text: 'page data'
},
methods: {
onLoad: function(options) {
// Executed when a page is created.
},
onPullDownRefresh: function() {
// Executed upon a pull-down refresh.
},
// Event response function
handleTap: function() {
// ...
}
}
}); getCurrentPages()
Obtains the current page stack. The last element in the array is the current page.
Since: 1.0.0