- 全局事件
// 第一个页面
onShow() {
const pageA1 = new BroadcastChannel('appChannel')
pageA1.postMessage('appShow')
},
onHide() {
const pageA2 = new BroadcastChannel('appChannel')
pageA2.postMessage('appHide')
},
// 第二个页面
onInit() {
console.log('main-tabs-onInit')
this.init()
const pageB = new BroadcastChannel('appChannel')
pageB.onmessage = (event) => {
pageB.postMessage('hello, i am here!')
if (event.data === 'appHide') {
clearInterval(this.timer)
}
if (event.data === 'appShow') {
this.init()
}
}
},