实现首页按两次返回键退出,其他页面按一次返回上一级
1、在main.js:
import Mui from 'vue-awesome-mui';
Vue.use(Mui);
Vue.prototype.$mui = Mui;
2、在App.vue首页:
mounted(){
var backcount = 0;
this.$mui.back = ()=> {
if (this.$mui.os.ios) return;
if (backcount > 0) {
if (window.plus) plus.runtime.quit();
return;
};
this.$layer.msg('再点击一次退出应用!')
backcount++;
setTimeout( () =>{
backcount = 0;
}, 2000);
};
}
3、在其他组件:
mounted(){
this.$mui.back = () => {
this.$router.go(-1);
};
}