// myComponents/tabBar/tabBar.js Component({ /** * 组件的属性列表 */ properties: { page:{ type:String, value:'/pages/index/index', observers:function(val){ this.changeTab(val) } } }, /** * 组件的初始数据 */ data: { current:'/pages/index/inde' }, /** * 组件的生命周期函数列表 */ lifetimes: { // 在组件实例进入页面节点树时执行 attached: function () { // 初始化操作 // console.log('组件初始化'); this.changeTab(this.properties.page) // ... }, // 在组件实例被移除出页面节点树时执行 detached: function () { // 清理工作 // console.log('组件销毁'); // ... }, // ... }, /** * 组件的方法列表 */ methods: { changeTab(key){ this.setData({ current:key, }) }, onChange(e) { console.log('onChange', e) this.changeTab(e.detail.key) wx.switchTab({ url: e.detail.key }) } } })