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);
    },
  • 相关阅读:
    如何在 Linux 上用 IP转发使内部网络连接到互联网
    python 基础-文件读写'r' 和 'rb'区别
    处理HTTP状态码
    国内可用免费语料库(已经整理过,凡没有标注不可用的链接均可用)
    java读取大文件
    struts.properties的参数描述
    ResourceBundle使用
    linux定时任务的设置
    杂记
    JAVA动态加载JAR包的实现
  • 原文地址:https://www.cnblogs.com/pycmsj/p/12641168.html
Copyright © 2011-2022 走看看