[Vuejs]-How to remove localStorage after timeout of a snackbar?

4👍

You can watch your reactive data alert. When the alert data is false, then you can clear the localStorage

export default {
 data(){
   return {
     alert: false
   }
 },
 watch:{
  alert(newValue){
     if(!newValue) clearLocalStorage()
  }
 },
 methods:{
   clearLocalStorage(){
     localStorage.removeItem('alert')
     localStorage.removeItem('alertColor')
     localStorage.removeItem('alertMessage')
   }
 }

}
👤Nico

Leave a comment