微信小程序(五)頁(yè)面生命周期詳細(xì)介紹
這里只要熟悉頁(yè)面的基本生命周期即可,業(yè)務(wù)在指定生命周期函數(shù)內(nèi)書(shū)寫(xiě)。
以下是官網(wǎng)給出的生命周期函數(shù)方法和狀態(tài)圖
上面的生周期函數(shù)圖對(duì)于做Android 或者IOS的來(lái)書(shū)理解起來(lái)應(yīng)該不是難事,具體怎么掌握只有慢慢嘗試和摸索
代碼處理:
這里的代碼主需要對(duì)使用創(chuàng)建項(xiàng)目時(shí)index目錄下文件處理下就行,至于跳轉(zhuǎn)后的頁(yè)面用的還是logs不需要更改!下面貼下代碼注釋也比較詳細(xì)
index.wxml
<!--index.wxml--> <view class="container"> <!--綁定點(diǎn)擊事件--> <view bindtap="bindViewTap" class="userinfo"> </view> <view class="usermotto"> <!--數(shù)據(jù)綁定--> <text class="user-motto">{{motto}}</text> </view> </view>
index.wxss
/**index.wxss**/ .container { width: 800; height: 800; } .userinfo { width: 120rpx; height: 120rpx; background: red; }
index.js
//index.js //獲取應(yīng)用實(shí)例 var app = getApp() Page({ /** * 通過(guò)data初始化數(shù)據(jù) */ data: { motto: '點(diǎn)擊上面View跳轉(zhuǎn)', // userInfo: {} }, //事件處理函數(shù) bindViewTap: function() { //通過(guò)調(diào)用API進(jìn)行跳轉(zhuǎn) wx.navigateTo({ url: '../logs/logs' }) }, /** * 監(jiān)聽(tīng)頁(yè)面開(kāi)在加載的狀態(tài) * 頁(yè)面加載完成之后就不會(huì)在執(zhí)行 */ onLoad: function () { console.log('index---------onLoad()') // //this指的就是本頁(yè)面對(duì)象 // var that = this // //調(diào)用應(yīng)用實(shí)例的方法獲取全局?jǐn)?shù)據(jù) // app.getUserInfo(function(userInfo){ // //更新數(shù)據(jù) // that.setData({ // userInfo:userInfo // }) // //更新本頁(yè)面 // that.update() // }) }, /** * 監(jiān)聽(tīng)頁(yè)面顯示, * 當(dāng)從當(dāng)前頁(yè)面調(diào)轉(zhuǎn)到另一個(gè)頁(yè)面 * 另一個(gè)頁(yè)面銷毀時(shí)會(huì)再次執(zhí)行 */ onShow: function() { console.log('index---------onShow()') }, /** * 監(jiān)聽(tīng)頁(yè)面渲染完成 * 完成之后不會(huì)在執(zhí)行 */ onReady: function() { console.log('index---------onReaday()'); }, /** * 監(jiān)聽(tīng)頁(yè)面隱藏 * 當(dāng)前頁(yè)面調(diào)到另一個(gè)頁(yè)面時(shí)會(huì)執(zhí)行 */ onHide: function() { console.log('index---------onHide()') }, /** * 當(dāng)頁(yè)面銷毀時(shí)調(diào)用 */ onUnload: function() { console.log('index---------onUnload') } })
相關(guān)文章:
hello WeApp icon組件
Window text組件 switch組件
tabBar底部導(dǎo)航 progress組件 action-sheet
應(yīng)用生命周期 button組件 modal組件
頁(yè)面生命周期 checkbox組件 toast組件
模塊化詳 form組件詳 loading 組件
數(shù)據(jù)綁定 input 組件 navigator 組件
View組件 picker組件 audio 組件
scroll-view組件 radio組件 video組件
swiper組件 slider組件 Image組件

微信小程序 開(kāi)發(fā)之滑塊視圖容器(swiper)詳解及實(shí)例代碼

js默認(rèn)文本框粘貼事件完美實(shí)現(xiàn)詳解

Meta開(kāi)源JavaScript內(nèi)存泄漏監(jiān)測(cè)工具M(jìn)emLab安裝使用

微信小程序 詳解Page中data數(shù)據(jù)操作和函數(shù)調(diào)用

9個(gè)JavaScript日常開(kāi)發(fā)小技巧

微信小程序 (一)新建項(xiàng)目hello WeApp 詳細(xì)介紹