One, the global configuration file App.js
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 programonShow(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 foregroundonHide()
Triggered when the applet enters the background from the foreground, the life cycle callback-monitor the applet and switch to the backgroundonError(String error)
Triggered when a script error occurs in the applet or an API call error occursonPageNotFound(Object object)
Triggered when the page to be opened by the applet does not existonUnhandledRejection(Object object)
Applet unprocessedPromise
rejecting trigger- In the
onShow
life cycle, incomingoptions
, print it out therepath
,query
,scene
,shareTicket
and so on,scene
the value is very important to explain in what way it is to go into the small program, that is how the scene is value, asscene: 1001
expressed discovery bar applet main entrance.shareTicket
Is the way of forwarding, WeChat group, etc. - By
getApp()
be a method to obtain a globally unique applet App instance, to use at the page level, asconst app = getApp();
- These are a small part of the overall program life cycle,
onLaunch()
,onShow()
,onHide()
MVVM
The idea of yes
Second, the page-level configuration file index.js
data
: Itdata
is the initial data used for the first rendering of the page. When the page is loaded, itdata
will beJSON
passed from the logic layer to the rendering layer in the form of a string. It must be ofJSON
type, such as string, number, boolean, object, array, etc.onLoad()
When the page loads trigger, a page is only called once, inonLoad
the parameters of the acquisition parameters of the current page open path, the life cycle callback - monitor page loadonReady()
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 layeronShow()
Life cycle callback-monitor page display, trigger when the page is displayed/cut to the foregroundonHide()
Life cycle callback-monitor page hidden, triggered when the page is hidden/cut into the backgroundonUnload()
Life cycle callback-monitor page unloading, triggered when the page is unloaded- Applet page-level life cycle functions including
onLoad()
,onShow()
,onReady()
,onHide()
,onUnload()
etc. onPullDownRefresh()
To monitor the user's pull-down action, it needsapp.js
towindow
be set in theenablePullDownRefresh
, astrue
onReachBottom()
The processing function of the bottoming event on the page, which needsapp.js
towindow
be set in theonReachBottomDistance
, which is 50 or another valueonShareAppMessage()
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'
}
}
onPageScroll()
Handle function of page scroll trigger eventonResize()
Triggered when the page size changesonTabItemTap()
Currentlytab
page, click ontab
the trigger, click on the applet event isbindTap
to 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"
})
}
- Applets modified
data
values is throughthis.setData()
to achieve modification, as in the above sample code