我有一個computed
方法:Vue的計算方法沒有得到所謂的
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;
}
}
}
這是越來越叫我<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>
,由於某種原因,當它被稱爲第一次,它的工作原理應該如何,但是當我嘗試再次調用它(重新渲染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;
}
}
}
它的工作原理應該如何試。
的this.get_local_storage_state()
功能看起來像這樣,位於methods:{}
:
get_local_storage_state(){
let state = localStorage.getItem('McDonaldsStoreWasOpen');
return state === "true" ? true : false;
}
我基本上是試圖使用本地存儲的狀態管理系統。
可能重複的[localStorage和布爾'字符串'](https://stackoverflow.com/questions/30644250/localstorage-and-boolean-string) – Terry