小程序3 App({}), Page({})

App({})

函数用来注册一个小程序

//app.js
App({
  onLaunch(options) {console.log(options)},
  onShow(options) {console.log(options)},
  onHide() {},
  onError(msg) {console.log(msg)},
  onPageNotFound(res) {
    wx.redirectTo({
      url: 'pages/...'
    }) // 如果是 tabbar 页面,请使用 wx.switchTab
  }
  globalData: 'I am global data'
})
//other.js
var appInstance = getApp()
console.log(appInstance.globalData) // I am global data

getCurrentPages

Page({})

//index.js
Page({
  customData: {
    hi: 'MINA'
  },
  data: {
    text: "This is page data."
  },
  onLoad: function(options) {console.log(options)},
  onReady: function() {},
  onShow: function() {},
  onHide: function() {},
  onUnload: function() {},
  onPullDownRefresh: function() {},//下拉刷新
  onReachBottom: function() {},//上拉触底
  onShareAppMessage: function () {},//自定义转发字段
  onPageScroll: function() {},//页面滚动
  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
    })
  }
})

Page.prototype.route
获取到当前页面的路径
Page.prototype.setData()
改变对应的 this.data 的值(同步)

this.setData({})

你可能感兴趣的:(小程序3 App({}), Page({}))