[Vuejs]-Unset img src if no url is provided vue.js

0👍

Unset the featuredImage before doing the load:

(function($){
  $(document).ready(function(){
    var app = new Vue({
      methods: {
        getContent: function(id){
          var self = this;

          // unset the image before you are loading.
          // this way it will also unset when the loading fails.
          self.featuredImage = null;

          var url = 'wp-json/wp/v2/pages/'+id+'?_embed';
          $.getJSON( url, function(data){
            self.featuredImage = data._embedded["wp:featuredmedia"][0].source_url;
          });
        }
      }
    });
  });
}(jQuery));

Leave a comment