Summary of the logical layer of the WeChat applet

One, the global configuration file App.js

  1. onLaunch(Object object) Triggered when the mini program is initialized, it is triggered only once globally, and the life cycle callback-monitor the initialization of the mini program
  2. onShow(Object object)
    Triggered when the applet is started or displayed in the foreground from the background, life cycle callback-monitor the applet to start or switch to the foreground
  3. onHide()
    Triggered when the applet enters the background from the foreground, the life cycle callback-monitor the applet and switch to the background
  4. onError(String error)
    Triggered when a script error occurs in the applet or an API call error occurs
  5. onPageNotFound(Object object)
    Triggered when the page to be opened by the applet does not exist
  6. onUnhandledRejection(Object object)
    Applet unprocessed Promiserejecting trigger
  7. In the onShowlife cycle, incoming options, print it out there path, query, scene, shareTicketand so on, scenethe value is very important to explain in what way it is to go into the small program, that is how the scene is value, as scene: 1001expressed discovery bar applet main entrance. shareTicketIs the way of forwarding, WeChat group, etc.
  8. By getApp()be a method to obtain a globally unique applet App instance, to use at the page level, asconst app = getApp();
  9. These are a small part of the overall program life cycle, onLaunch(), onShow(),onHide()
  10. MVVMThe idea of yes

Second, the page-level configuration file index.js

  1. data: It datais the initial data used for the first rendering of the page. When the page is loaded, it datawill be JSONpassed from the logic layer to the rendering layer in the form of a string. It must be of JSONtype, such as string, number, boolean, object, array, etc.
  2. onLoad()
    When the page loads trigger, a page is only called once, in onLoadthe parameters of the acquisition parameters of the current page open path, the life cycle callback - monitor page load
  3. onReady()
    Life Cycle Callback—Monitor the first rendering of the page is completed, triggered when the first rendering of the page is completed, a page can only be called once, and can interact with the view layer
  4. onShow()
    Life cycle callback-monitor page display, trigger when the page is displayed/cut to the foreground
  5. onHide()
    Life cycle callback-monitor page hidden, triggered when the page is hidden/cut into the background
  6. onUnload()
    Life cycle callback-monitor page unloading, triggered when the page is unloaded
  7. Applet page-level life cycle functions including onLoad(), onShow(), onReady(), onHide(), onUnload()etc.
  8. onPullDownRefresh()
    To monitor the user's pull-down action, it needs app.jsto windowbe set in the enablePullDownRefresh, astrue
  9. onReachBottom()
    The processing function of the bottoming event on the page, which needs app.jsto windowbe set in the onReachBottomDistance, which is 50 or another value
  10. onShareAppMessage()
    The user clicks on the upper right corner to forward, sample code
onShareAppMessage: function (res) {
    
    
    if (res.from === 'button') {
    
    
      // 来自页面内转发按钮
      console.log(res.target)
    }
    return {
    
    
      title: '自定义转发标题',
      path: '/page/user?id=123'
    }
}
  1. onPageScroll()
    Handle function of page scroll trigger event
  2. onResize()
    Triggered when the page size changes
  3. onTabItemTap()
    Currently tabpage, click on tabthe trigger, click on the applet event is bindTapto trigger, and
    sample code
<view class="container" bindtap="showTest">
  {
   
   { motton }}
</view>
test: "hello word",
showTest() {
    
    
    // console.log(this.test)
    this.setData({
    
    
      motton: "a better vue"
    })
 }
  1. Applets modified datavalues is through this.setData()to achieve modification, as in the above sample code

Guess you like

Origin blog.csdn.net/weixin_42614080/article/details/109664483