文章內(nèi)容:uni-app生命周期和模版語法
uni-app 支持如下頁面生命周期函數(shù):
onLoad 監(jiān)聽頁面加載兽赁,其參數(shù)為上個頁面?zhèn)鬟f的數(shù)據(jù)韩脏,參數(shù)類型為object(用于頁面?zhèn)鲄ⅲ└Q梗瑓⒖际纠?br>
onShow 監(jiān)聽頁面顯示
onReady 監(jiān)聽頁面初次渲染完成
onHide 監(jiān)聽頁面隱藏
onUnload 監(jiān)聽頁面卸載
onPullDownRefresh 監(jiān)聽用戶下拉動作
onReachBottom 頁面上拉觸底事件的處理函數(shù)
onShareAppMessage 用戶點擊右上角分享 微信小程序
onPageScroll 監(jiān)聽頁面滾動
onTabItemTap 當前是 tab 頁時,點擊 tab 時觸發(fā)较性。
<script>
export default {
data: {
msg: 'Hello'
},
onLoad:function(options){
console.log("onLoad");
},
onHide:function(){
console.log("onHide");
},
onShow:function(){
console.log("onShow");
}
}
</script>
數(shù)據(jù)綁定
變量賦值
<script>
export default {
data: {
title: 'Hello',
}
</script>
視圖渲染數(shù)據(jù):
<template>
<view class="content">
<view>
{{title}}
</view>
</view>
</template>
數(shù)組形式的數(shù)據(jù)綁定:
<tamplate>
<view>
{{list[0]['name']}}
{{list[0].name}}
</view>
</template>
<script>
export default{
data: {
list : [
{name : "張三", age : 18},
{name : "李四", age : 20}
]
},
}
</script>