I'm facing an issue with saving my input to the cache memory. I attempted to utilize the mounted
method, but it's not performing as desired because it fails to retain the last input in memory; upon refreshing the page, the last input gets erased. It's possible that I'm making a mistake since I've only just started learning Vue a day ago. Can someone please clarify what's incorrect here or provide guidance on how to rectify it?
export default {
name: 'Skills',
data() {
return {
skill: '',
skills: [
{ 'skill': 'Vue.js' },
{ 'skill': 'Frontend Developer' }
]
}
},
mounted() {
if (localStorage.skill) {
this.skill = localStorage.skill;
}
},
methods: {
addSkill() {
this.$validator.validateAll().then((result) => {
if (result) {
this.skills.push({skill: this.skill})
this.skill = '';
} else {
console.log('Not valid')
}
})
}
}
}
I am utilizing code from an example where my v-model in the input is "skill." How can I create a method that correctly saves the last input in the cache? I wish to be able to add a new skill to the array and still see the value persist in the array even after refreshing the page. Is this achievable, and if so, how can it be done? I am completely new to Vue and would appreciate any assistance.