[Vuejs]-How to clear all the local storage input fields while we submit the form

1👍

Set those localStorage fields to empty strings in submitForm():

methods() {
  submitForm: function() {
    axios({
      /*...*/
    }).then(response => {
      localStorage.category = '';
      localStorage.title = '';
      localStorage.address = '';
      localStorage.city = '';
      localStorage.state = '';
      localStorage.zip = '';
      localStorage.price = '';
      localStorage.description = '';
      this.category = '';
      this.title = '';
      this.address = '';
      this.city = '';
      this.state = '';
      this.zip = '';
      this.price = '';
      this.description = '';

      /*...*/
    }).catch(error => {
      /*...*/
    })
    
  }
}
👤tony19

2👍

From MDN docs on localStorage, use:

localStorage.clear()

This still won’t reset your vue data until the page is refreshed. You will have to do that separately.

Leave a comment