mui進行手機物理鍵的監聽javascript
確保引入muijava
調用如下函數android
// android 返回按鍵處理 androidBack(store, data) { try { mui.init({ keyEventBind: { backbutton: true //關閉back按鍵監聽 } }); // alert(plus.os.name) var first = null; mui.back = function () { let path = state.crunchies.setPageCon; let isOut = path == 'home' || path == 'crunchies' || path == 'Information' || path == 'warning' || path == 'mine'; // mui.toast(path); //給出提示 if (!first) { first = new Date().getTime(); //記錄第一次按下回退鍵的時間 // mui.toast('再按一次退出應用'); //給出提示 if (!isOut) { store.dispatch("actionsBackJump", { router: data.router, id: 'back' }) } setTimeout(function () { //1s中後清除 first = null; }, 1000); } else { if (new Date().getTime() - first < 1000) { //若是兩次按下的時間小於1s, plus.runtime.quit(); //那麼就退出app } } }; } catch (error) {} }