cordova app页面后退及退出功能

vue代码

let exitAppTicker = 0
document.addEventListener("deviceready", () => {
    document.addEventListener("backbutton", () => {
        //判断当前路由是否为首页或者登录页面
        if (this.$route.path == '/index' || this.$route.path == '') {
            if (exitAppTicker == 0) {
                exitAppTicker++;
                this.$toast({
                    message: '再按一次退出',
                });
                setTimeout(() => {
                    exitAppTicker = 0;
                }, 1000);
            } else if (exitAppTicker == 1) {
                navigator.app.exitApp(); //退出app
            }
        } else {
            this.$router.go(-1)
        }
    }, false);
}, false);