Я бы выбрал совершенно другой подход, поскольку, прежде всего, используя :set
, ваши http-запросы будут запускаться всякий раз, когда происходит обнаружение изменений. Вместо этого соберите все данные при визуализации компонента:
created() {
this.getStores();
},
methods: {
getProducts(id) {
return axios.get("...")
.then(response => response.data)
},
getStores() {
// first get stores, you can also use async await instead, if you like
axios.get("...").then(response => {
this.stores = response.data;
// gather all requests for each store to get products
const reqs = this.stores.map(store => this.getProducts(store.id));
axios.all(reqs).then(products => {
// merge data
this.stores = this.stores.map((store, i) => {
return { ...store, products: products[i] };
});
});
});
}
}
Теперь для каждого магазина есть свойство products
:
<div v-for="store in stores" :key="store.id">
<h2>{{store.name}}</h2>
<ul>
<!-- choose a key, here just using index -->
<li v-for="(product, index) in store.products" :key="index">
{{product.category.name}}
</li>
</ul>
</div>
Что касается шаблона, убедитесь, что category.name
фактически существует в объекте продукта.