Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

268
Views
How to remove localStorage after timeout of a snackbar?

enter image description here

I'm using this Vuetify <v-snackbar, I triggered it base on values that I stored in localStorage.

/create

After I created my object

Ex.

localStorage.setItem('alert', true)
localStorage.setItem('alertColor', 'green')
localStorage.setItem('alertMessage', this.form.values.name + ' - created successfully!')

With these codes

<v-snackbar timeout="2000" v-model="alert" absolute top :color="alertColor" outlined right>
    <strong>
        {{ alertMessage }}
    </strong>
</v-snackbar>

/index (list)

I checked localStorage and show a proper alert message + color.

export default {
    data() {
        return {
            alert: localStorage.getItem('alert'),
            alertColor: localStorage.getItem('alertColor'),
            alertMessage: localStorage.getItem('alertMessage'),

After timeout="2000" my alert hide, I would like to remove my localStorage so when I refresh the page, I don't see that same alert again.

localStorage.removeItem('alert')
localStorage.removeItem('alertColor')
localStorage.removeItem('alertMessage')
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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')
   }
 }

}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!