[Vuejs]-Get Local Storage Data when internet is online

0👍

You can handle this (update onLine status) by using event listener and set the variable true/false.
Later you can watch to the data property and do something accordingly.

  data() {
    return {
      isOnLine:navigator.onLine
    }
  },
  mounted() {
     window.addEventListener('online', () => {this.isOnLine = true});
     window.addEventListener('offline', () => {this.isOnLine = false});
  },
  watch: {
   onLine: function (val) {
      if(this.isOnLine){
        // make axios call here
      }
    },
  }

Leave a comment