After the browser page refreshes, data recovers.

In

Vue.js, refresh the page and the data in data will be restored.

data(){
  return {
    value: "",
  }
},

I have a component"s data data value,. When I"m in this component, I use button events to add data to it

  click_btn(){
    this.value = this.value + "123"
  }
  

but when I refresh the browser page, it reverts to the previous empty string. How to solve this problem?

Mar.03,2021

click_btn(){
    this.value = this.value + '123'
    window.sessionStorage.setItem('val',this.value)
  }
mounted(){
    if(window.sessionStorage.getItem('val')){
        this.value = window.sessionStorage.getItem('val');
    }
}
The data in

data is stored in memory, and will definitely be recovered after refreshing. It can only be persisted, and can only be stored in localstorage or cookie

.
Menu