The task is to ensure that the value entered in input is saved when entered into vuex and already in vuex saved in localstorage , and then if the application was closed, then when reopened, the value stored in localstorage should be returned to input . Now for some reason my input value is not saved. Please tell me what I'm doing wrong or, if possible, correct the code. Thank!
Component itself
<f7-list-input placeholder="Username" type="text" v-bind:value="name" @input="onPersist" /> export default { mounted() { if (localStorage.name) { this.name = localStorage.getItem('name'); } }, computed:{ name(){ return this.$store.state.name; } }, methods:{ onPersist(){ this.$store.commit('persist',event.target.value); } } }; </script>
VUEX storage
export default new Vuex.Store({ state: { name: '' }, mutations: { persist(state,payload){ state.name = payload; localStorage.setItem('name', state.name); }, } });