[Vuejs]-Vue js – Data from post request will not render

0👍

I solved this on a stroke of luck, I still don’t know why this wasn’t working but the point is that now it does, this is the new Vue instance:

var immobles_destacats = ($('#immobles_destacats').length > 0) ? new Vue({
  el: '#immobles_destacats',
  data: {
    immobles: []
  },
  methods: {
    add: function(i) {
      alert(this.immobles[i].imatges.lenght)
      alert(this.immobles[i].counter)
      if (this.immobles[i].imatges.lenght == this.immobles[i].counter) {
        return this.immobles[i].counter = 0;
      }
      return this.immobles[i].counter++;
    },
    substract: function(i) {
      alert(this.immobles[i].counter)
      if (this.immobles[i].counter == 0) {
        return this.immobles[i].counter = this.immobles[i].imatges.lenght;
      }
      return this.immobles[i].counter--;
    }
  },
  mounted: function() {
    $.post('get_immobles_destacats', function(immobles, textStatus, xhr) {
      for (var i = 0; i < immobles.length; i++) {
        immobles[i].counter = 0;
        immobles_destacats.immobles.push(immobles[i]);
      }
    });
  }
}) : null;

Notice that now I push the object and I set the counter before pushing it.
Also, data ‘immobles’ is now an array, not an object

👤Neku80

Leave a comment