从主页(index)进入另外一个组件 ( s )后,然后返回到主页( index ),已经走 console.log(999999999) 了,但plus.key.addEventListener('backbutton',exitApp)这个事件没有添加上去
//这是路由
document.addEventListener('plusready', function(){
router.goBackk = router.goBack.bind(router)
// plus.key.addEventListener('backbutton',exitApp)
router.beforeEach((to,from,next)=>{
if(window.plus){
plus.key.removeEventListener('backbutton',exitApp)
plus.key.removeEventListener('backbutton',router.goBackk)
}
if(to.name === 'index' || to.name === 'select' || to.name === 'activity' || to.name === 'mine'){
console.log(1111111)
if(window.plus){
console.log(999999999)
plus.key.addEventListener('backbutton',exitApp)
}
}else if(to.meta.queryWin){
console.log(2222222)
}else{
console.log(333333)
if(window.plus){
plus.key.addEventListener('backbutton',router.goBackk)
}
}
next()
})
},false)
//这是其中的页面 name 为 s
deactivated(){
if(window.plus){
let _self = this
console.log(5555555)
console.log(_self.offf)
plus.key.removeEventListener('backbutton', _self.offf)
// plus.key.addEventListener('backbutton', $backfn,false)
}
},
activated(){
this.offf = this.back.bind(this)
if(window.plus){
let _self = this
console.log(444444)
plus.key.addEventListener('backbutton', _self.offf)
}
},
methods: {
back(){
this.off = !this.off
this.$router.goBack()
},
c(){
if(window.plus){
let _self = this
console.log(5555555)
console.log(_self.offf)
plus.key.removeEventListener('backbutton', _self.offf)
// plus.key.addEventListener('backbutton', $backfn,false)
}
}
}
1 个回复
DCloud_UNI_CHB
仅判断window.plus没用,需要同时监听plusReady事件,参考mui.plusReady方法。