WeChat applet] [007 - set button and the page lifecycle methods

Button Settings

1. Use a text element to display a button click event handler and bind f0

By providing text bindtap element binding function attributes
sample code (wxml):

<text bindtap="f0" wx:if="{{index < (weeklyMovieList.length - 1)}}" class="return-button">返回本周</text>

2. The provisions button style

Sample Code (wxss):

.button{
  position: absolute;
  right: 10rpx;
  top: 80rpx;
  font-size: 30rpx;
  color: lightcoral;
  border:1px solid coral;
  border-radius: 20%;
}

Event handler

1. On page logical file Page function in settings

  f0: function(event){
    this.setData({
      currentIndex: this.data.weeklyMovieList.length-1
    })
  }

Page lifecycle methods

It can be understood as a special event handler

1. onLoad

  • In the page logic file Page function in settings
  • Only called once when the page is initialized
  • Sample Code
onLoad: function(options){
  this.setData({
    currentIndex: this.data.weeklyMovieList.length-1
  })
}

NOTE: use this.setData ({}) to operate on the internal state variables assigned, so as to synchronize updates view

2. onShow

  • In the page logic file Page function in settings
  • Is called each time the page is loaded

3. onReady

  • In the page logic file Page function in settings
  • When the initial page load is complete, ready to be called interaction

the fourth one hydrochloride

  • In the page logic file Page function in settings
  • Is called every time the page Hide

4. onUnload

  • In the page logic file Page function in settings
  • When the page is turned off or is unloaded to be called

Guess you like

Origin www.cnblogs.com/codaland/p/12632496.html