zoukankan      html  css  js  c++  java
  • vue+cordova实现退出app效果

    //vue钩子函数created方法中添加监听等待设备API库加载好
    created(){
      var that = this;
      document.addEventListener("deviceready", that.onDeviceReady, false);
    }
    methods:{
        //设备API可以使用了,然后在vue的methods中添加如下方法
      onDeviceReady() {
        var that = this;
           document.addEventListener("backbutton", that.eventBackButton, false);
      },
      //监听返回键按钮事件
      eventBackButton(){
        var that = this;
           that.$toast('再按一次退出');//这里使用的是vantUI框架的弹窗提示,此处可根据自身项目进行更改
           document.removeEventListener("backbutton", that.eventBackButton, false); //注销返回键
           document.addEventListener("backbutton", that.exitApp, false);//绑定退出事件
           var intervalID = setInterval(() => {
             document.clearInterval(intervalID);
             document.removeEventListener("backbutton", that.exitApp, false);
             document.addEventListener("backbutton", that.eventBackButton, false);
           },2000);
      },
      // 关闭app
      exitApp() {
          var that = this;
          navigator.app.exitApp();
      }
    }
    //页面离开时销毁监听事件
    destroyed() {
      var that = this;
      document.removeEventListener("backbutton", that.exitApp, false);
      document.removeEventListener("backbutton", that.eventBackButton, false);
    },
  • 相关阅读:
    sql日期操作
    用户活跃状态模型
    R基于Bayes理论实现中文人员特性的性别判定
    python的一点小常识
    [工作技能]SVN
    北大计算所词性标注集简表
    c++ boost 汉字和模式串混用的例子
    SVN文本文件报二进制属性的问题
    我的R代码备份
    FaceBook Twitter实习生简历求内推
  • 原文地址:https://www.cnblogs.com/pycmsj/p/12641168.html
Copyright © 2011-2022 走看看