注意注意注意!用Component构造器构造界面时,js里的Page一定要改成Component!!!!!!!!!!!component的onload(attached)要写到lifetimes中,attached是component的onload方法,attached优于onload先执行的。
const app = getApp()
Component({
data: {
index: [{
pagePath: "/pages/index/index",
iconPath: "/images/homeIcon.png",
selectedIconPath: "/images/homeIconSelected.png",
text: "首页"
},
{
pagePath: "/pages/store/store",
iconPath: "/images/storeIcon.png",
selectedIconPath: "/images/storeIconSelected.png",
text: "商城"
},{
pagePath: "/pages/personalCenter/personalCenter",
iconPath: "/images/perIcon.png",
selectedIconPath: "/images/perIconSelected.png",
text: "我的"
}]
},
properties: {
},
lifetimes:{
attached:function (e) {
}
},
pageLifetimes: {
show() {
if (typeof this.getTabBar === 'function' &&
this.getTabBar()) {
this.getTabBar().setData({
list:this.data.index,
selected: 0
})
}
}
},
methods:{
},
onShow: function () {
},
onLoad: function () {
}
})
微信开发者工具中这样讲:
Component({
behaviors: [],
properties: {
myProperty: {
type: String,
value: ''
},
myProperty2: String
},
data: {},
lifetimes: {
attached: function () { },
moved: function () { },
detached: function () { },
},
attached: function () { },
ready: function() { },
pageLifetimes: {
show: function () { },
hide: function () { },
resize: function () { },
},
methods: {
onMyButtonTap: function(){
this.setData({
})
},
_myPrivateMethod: function(){
this.setData({
'A[0].B': 'myPrivateData'
})
},
_propertyChange: function(newVal, oldVal) {
}
}
})
|