1***@qq.com
1***@qq.com
  • 发布:2018-01-06 15:55
  • 更新:2018-01-08 13:38
  • 阅读:2860

vue开发的单页面项目,在处理物理返回键的时候出错,

分类:HTML5+

从主页(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)  
                  }  
            }  
        }
2018-01-06 15:55 负责人:无 分享
已邀请:
DCloud_UNI_CHB

DCloud_UNI_CHB

仅判断window.plus没用,需要同时监听plusReady事件,参考mui.plusReady方法。

该问题目前已经被锁定, 无法添加新回复