在vue中通过v-if去控制元素的显示,但这次出现没有生效,
我是通过获取本地缓存值
created() {
this.getList();
this.isPersonal=localStorage.getItem('isPersonal')
},
通过console.log(this.ispersonal)也能正常输出对应的true 或者false,但始终前端元素没有得到效果,开始以为是vue加载顺序原因,使用了
mounted(){}中运行依然不行。
后来发现通过本地缓存获得的值是一个字符串的“true”和“false”,将字符串转换为布尔值
created() {
this.getList();
this.isPersonal=JSON.parse(localStorage.getItem('isPersonal'))
},
ok,成功了