JavaScript Vue computed method not getting called

I have a computed method:

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;
    }
  }
}

Which is getting called in my <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>

And for some reason, when it gets called the first time, it works how it should, however when I try calling it again (re-rendering the Vue component) it doesnt get called.

BUT!

When I comment out the first if() statement, like so:

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;
    }
  }
}

It works how it should again.

The this.get_local_storage_state() function looks like this and is located in methods:{}:

get_local_storage_state(){
  let state = localStorage.getItem('McDonaldsStoreWasOpen');
  return state === "true" ? true : false;
}

I am basically trying to use local storage as a state management system.

Answer:1

This code form is working, but it doesn't call the ajax form chat_process.php. I need to call the ajax form and alert a message. var html = ""; for(...) { html += '<form class="...

This code form is working, but it doesn't call the ajax form chat_process.php. I need to call the ajax form and alert a message. var html = ""; for(...) { html += '<form class="...

  1. ajax form not working
  2. ajax form not working mvc
  3. ajax form submit not working
  4. ajax form serialize not working
  5. ajax form submit not working mvc
  6. ajax form preventdefault not working
  7. ajax form success not working
  8. ajax form post not working
  9. ajax form validation not working
  10. ajax form plugin not working
  11. ajax beginform not working
  12. ajax acf_form not working
  13. django ajax form not working

I am using the demo code for intlTelInput provided here I am able to get the dial code using following var intlNumber = $("#phone").intlTelInput("getSelectedCountryData"); But i am not ...

I am using the demo code for intlTelInput provided here I am able to get the dial code using following var intlNumber = $("#phone").intlTelInput("getSelectedCountryData"); But i am not ...

Cannot reproduce MDN's example («Using an object in an array-like fashion»). let obj = { length: 0, addEl: function (element) { [].push.call(this, element); }; }; // Node ...

Cannot reproduce MDN's example («Using an object in an array-like fashion»). let obj = { length: 0, addEl: function (element) { [].push.call(this, element); }; }; // Node ...

  1. call using push

I would like to start tracking e-commerce with Google Analytics, to do this I need to pass the values of my data layer into GA using GTM. I have read endless amounts of documentation on the subject ...

I would like to start tracking e-commerce with Google Analytics, to do this I need to pass the values of my data layer into GA using GTM. I have read endless amounts of documentation on the subject ...

  1. ecommerce tracking with google tag manager
  2. ecommerce tracking with google analytics
  3. ecommerce tracking with tag manager
  4. ecommerce tracking with analytics
  5. ecommerce tracking tag manager