<el-select @change="store(types)" v-model="types" placeholder="Select">
<el-option
v-for="t in types"
:label="t.name"
:value="t"
>
</el-option>
我正在使用方法存储将所选选项保存到localstorate:
store(value){
var name = value.name;
var selected = localStorage.setItem('plan', name); // String
},
当我刷新页面或返回此页面时,我希望选择之前选择的选项。我怎么能用VueJS做到这一点?
答案 0 :(得分:0)
您需要从localStorage获取存储的值并将其设置在created()hook
中created () {
this.types = localStorage.getItem('plan')
}
有关挂钩的更多信息, https://vuejs.org/v2/guide/instance.html#Instance-Lifecycle-Hooks