All Products
Search
Document Center

Mobile Platform as a Service:Page introduction

Last Updated:Feb 03, 2021

Page represents a page of the app and is responsible for page presentation and interaction. Each page corresponds to one subdirectory. The number of pages is equal to the number of subdirectories. The Page component is also a constructor function used to generate a page instance.

In general, each Mini Program page consists of the following files:

  • [pageName].js: page logic
  • [pageName].axml: page structure
  • [pageName].acss: (Optional) page format
  • [pageName].json: (Optional) page configurations

Provide the data specified in the following code during initialization of a page.

  1. Page({
  2. data: {
  3. title: 'mPaaS',
  4. array: [{user: 'li'}, {user: 'zhao'}],
  5. },
  6. });

Render the content on the page based on the preceding data.

  1. <view>{{title}}</view>
  2. <view>{{array[0].user}}</view>

Specify a response function when you define an interactive behavior.

  1. <view onTap="handleTap">click me</view>

The preceding code indicates that the handleTap method is invoked when a user touches a button on the page.

  1. Page({
  2. handleTap() {
  3. console.log('yo! view tap!');
  4. },
  5. });

During re-rendering on the page, invoke the this.setData method in the script of the page.

  1. <view>{{text}}</view>
  2. <button onTap="changeText"> Change normal data </button>

The preceding code indicates that the changeText method is invoked when a user touches a button on the page.

  1. Page({
  2. data: {
  3. text: 'init data',
  4. },
  5. changeText() {
  6. this.setData({
  7. text: 'changed data',
  8. });
  9. },
  10. });

In the preceding code, invoke the this.setData method in the changeText method causes the page to be re-rendered.