[Vuejs]-Not returning value in vue function

0👍

Apart from the fact that product.user_id is undefined as stated in the comment, you have another issue.

getProductUser doesn’t return an email. It returns a promise that will provide an email.

Simplest solution would be

<td>
  {{ product.userEmail }}
</td>

(which is by the way an equivalent to <td v-text="product.userEmail"/>, vue templates can be much cleaner than standard HTML).

  getProducts(){
    axios.get('/api/products/'+this.id+'/product').then(response => {
      this.products = response.data.products;

      this.products.forEach(product => {
        axios.get('/api/product/'+user).then(response => {
          product.userEmail = response.data.email;
        });
      })
    });

This should work, but keep in mind that executing additional request per product is generally a bad idea, the performance would be much better if /api/products/{id}/product would have userEmail property already initialized.

Leave a comment