Jou*_*usi 2 javascript state vue.js computed-properties vuejs2
我有一个computed
方法:
computed: {
currentPosition () {
if(this.get_local_storage_state()){
return this.lastLocation
}
if (this.currentRestaurant) {
return this.currentRestaurant.address.location
} else if (this.searchPosition.lat && this.searchPosition.lon) {
return this.searchPosition;
} else {
return null;
}
}
}
Run Code Online (Sandbox Code Playgroud)
哪个在我的电话中被调用<template>
:
<GMap class="c-splitview__map" :markers="getMarkers" :position="currentPosition" :zoom="currentZoom" v-if="currentPosition" />
<div class="m-storefinder__placeholder" v-else>
<h1 class="o-headline">{{$tc("storefinder.emptyDeeplink")}}</h1>
</div>
Run Code Online (Sandbox Code Playgroud)
并且出于某种原因,当它第一次被调用时,它的运行方式应该如何,但是当我再次尝试调用它时(重新渲染Vue组件)它不会被调用.
但!
当我注释掉第一个if()
语句时,如下:
computed: {
currentPosition () {
// if(this.get_local_storage_state()){
// return this.lastLocation
// }
if (this.currentRestaurant) {
return this.currentRestaurant.address.location
} else if (this.searchPosition.lat && this.searchPosition.lon) {
return this.searchPosition;
} else {
return null;
}
}
}
Run Code Online (Sandbox Code Playgroud)
它的工作原理应该如何.
该this.get_local_storage_state()
函数如下所示,位于methods:{}
:
get_local_storage_state(){
let state = localStorage.getItem('McDonaldsStoreWasOpen');
return state === "true" ? true : false;
}
Run Code Online (Sandbox Code Playgroud)
我基本上试图使用本地存储作为状态管理系统.
归档时间: |
|
查看次数: |
546 次 |
最近记录: |