APP打包工具:hbuilder
需要js包:mui.js ,引入方法https://www.cnblogs.com/v616/p/11290281.html
实现原理:在vue根组件App.vue监听安卓机,按后退键时候vue的路由path
代码App.vue
代码片段: data() { return { tabbarShow:true, arrTab:['/home','/cat','/history','/me'] }; }, mounted(){ // 安卓后退键 this.$mui.plusReady( () =>{ var backcount = 0; this.$mui.back = ()=> { let path = this.$route.path; console.log("path:"+path); if (this.arrTab.includes(path)) { // 主导航页 if (this.$mui.os.ios) return; if (backcount > 0) { if (window.plus) plus.runtime.quit(); return; }; this.$toast('再点击一次退出应用!'); backcount++; setTimeout( () =>{ backcount = 0; }, 2000); } else { // 子页面 console.log('子页面后退键'); this.$router.go(-1); } }; }) },