话不多说,直接上代码:
npm install vue-awesome-mui
import Mui from 'vue-awesome-mui';
Vue.use(Mui);
router.beforeEach((to, from, next) => {
var quit = false
mui.back = function () {
if (!quit) {
// home和line为首页一级路由name值
if (to.name == 'home' || to.name == 'line') {
mui.toast("再按一次退出应用")
quit = true
setTimeout(function () {
quit = false
}, 2000)
} else {
if (to.matched[0].instances.default.showmask) {
to.matched[0].instances.default.showmask = false
} else {
history.go(-1); // 返回上一页
}
}
} else {
plus.runtime.quit(); //退出app
}
}
next()
})