I currently am using a function on a timed loop to check if a user goes offline:

```
created() {
   setInterval(() => {
        this.checkOnline();
   }, 30000);
}

```

Method:

```
checkOnline(){
   this.onLine = navigator.onLine ? true : false;
}

```

Is there a way I can detect this without using the timer?

Secondly...

I am trying to show an 1 second alert to tell the user they are back online. When this.onLine is true, the div should be hidden. When it is false it should also be hidden, but when it goes from false to true I want to show the div for a second or so and then hide it again. I have tried this with a settimeout and using a watcher but neither give the desired effect.

**Edit:**

So one method that gets me there is:

```
 data() {
     return {
         onLine: navigator.onLine ? true : false,
     }
 }

```

then a watcher to show the back online message

```
watch: {
    onLine: function (val) {
        if(this.onLine === true){
            this.showBackOnline = true;
            setTimeout(()=>{ this.showBackOnline = false; }, 1000);
        }
    },
},

```

Is there a better way than a watcher to achieve this, other than using a dedicated notify plugin?