使用了 uni-simple-router
后只需要监听路由堆栈就可以实现监听退出应用
const backInfo = {
number: 1,
};
const router = createRouter({
platform: process.env.VUE_APP_PLATFORM,
// detectBeforeLock: () => {
// router.$lockStatus = false;
// },
routerErrorEach: (error, router) => {
if (error.type === 3) {
router.$lockStatus = false;
// #ifdef APP-PLUS
if (backInfo.number > 1) {
plus.runtime.quit();
} else {
backInfo.number += 1;
plus.nativeUI.toast("再按一次退出应用");
}
setTimeout(function () {
backInfo.number = 1;
}, 1000);
// #endif
}
},
routes: [...modules],
});
一个简易的再按一次退出应用就可以实现了