Every time my vm is created, the computed values get function fails to run, leaving the value unassigned.
Oddly enough, it does run when I attempt to access the value, just not during the initial app startup.
Essentially, the goal is to calculate the skin value and dynamically update the stylesheet link to load the correct skin on startup or change.
The functionality is there, but the issue lies in the lack of execution during startup. Should I resort to a workaround like fetching the value in the mounted function of the vm? Or am I overlooking something...
computed: {
skin: {
get: function () {
var mySkin = "my/skin/string";
if (window.localStorage.getItem("skin") === null) {
window.localStorage.setItem("skin", mySkin);
jquery("link[id='skin']").attr("href", "css/skins/" + mySkin + ".css");
} else {
mySkin = window.localStorage.getItem("skin");
window.localStorage.setItem("skin", mySkin);
jquery("link[id='skin']").attr("href", "css/skins/" + mySkin + ".css");
}
var hey = this.skin;
return mySkin;
},
set: function (val) {
window.localStorage.setItem("skin", val);
jquery("link[id='skin']").attr("href", "css/skins/" + val + ".css");
}
}
}