[Vuejs]-Change value with ajax in v-for loop

2👍

I think a filter is the wrong tool for what you’re trying to do. Ordinarily, if you want an element based on the value of another element, you’d use a computed, but I think the async population of a computed is going to be a problem. You’ll need to use a real data item and populate it in a watch of publications. Something like:

data: {
  ...
  productData: []
},
watch: {
  publications: function (newValue) {
    this.productData = [];

    this.publications.forEach((pub, i) => {
      this.$http.get('/api/product/'+pub.productId)
      .then((rst) => {
        this.productData[i] = rst.data.name;
      }
    });
  }
}

Then your for would be like:

<div v-for="name in productData">
  {{ name }}
</div>
👤Roy J

Leave a comment