0👍
Computed property is a property which depends on data properties.
In your case it is better IMO to create a data
property skin
, and a method like setSkin()
which initializes the skin
data property, and another method saveSkin()
to save your property into localStorage.
You then can run setSkin()
in mounted()
hook.
Template:
new Vue({
el: '#app',
data: {
skin: ''
},
methods: {
setSkin: function() {
this.skin = ...;
},
saveSkin: function() { // call this function when you need to save skin data into localStorage
window.localStorage.setItem("skin", this.skin);
....
}
},
mounted() {
this.setSkin(); // retrieve skin data from localStorage, etc.
}
});
Source:stackexchange.com