How to save new value to data variables in Vue.js whenever the user types?

Technology CommunityCategory: Vue.jsHow to save new value to data variables in Vue.js whenever the user types?
VietMX Staff asked 3 years ago

Use watch method to detect changes on variable you are storing data on like this:

watch: {
  input: function () {
    if (isLocalStorage() /* function to detect if localstorage is supported*/) {
      localStorage.setItem('storedData', this.input)
    }
  }
}