cordova plugin add cordova-plugin-network-information

  

 mounted(){
  this.checkConnection()
  document.addEventListener("offline", this.onOffline(), false);
 }

  

    checkConnection (){
        let networkState = navigator.connection.type;
        let states = {};
        states[Connection.UNKNOWN]  = 'Unknown connection';
        states[Connection.ETHERNET] = 'Ethernet connection';
        states[Connection.WIFI]     = 'WiFi connection';
        states[Connection.CELL_2G]  = 'Cell 2G connection';
        states[Connection.CELL_3G]  = 'Cell 3G connection';
        states[Connection.CELL_4G]  = 'Cell 4G connection';
        states[Connection.CELL]     = 'Cell generic connection';
        states[Connection.NONE]     = 'No network connection';
        if(networkState==Connection.NONE){
          alert('主人,又没网络啦')
        }else {
          alert('网络类型' + states[networkState]);
        }
      },
      onOffline(){
        let networkState = navigator.connection.type;
        if (networkState === Connection.NONE) {
          alert('主人,又没网络啦')
        }
      }

  

相关文章:

  • 2022-12-23
  • 2021-06-01
  • 2021-11-01
  • 2021-06-16
  • 2021-07-29
  • 2021-06-02
  • 2021-08-20
猜你喜欢
  • 2022-01-07
  • 2021-10-03
  • 2021-08-21
  • 2022-03-02
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案