Answer the question
In order to leave comments, you need to log in
How to get items from another directory?
Good time! I use vue, vue-resource, no vue-router. The task, after requesting a catalog of product categories (sweet, salty, etc.) category.json
, is to get product elements (sweets, cookies, etc.) products.json
from another catalog by clicking on the corresponding category.
In my example, the list of categories is loaded first:
created(){
this.$http.get('category.php')
.then (response => response.json())
.then (data => {
this.products = data
console.log(this.products)
}, (error) => {
console.log(error);
})
}
viewProduct(section_id) {
this.$http.get('product.json')
.then (response => response.json())
.then (data => {
this.product = data.section_id
console.log(this.product)
}, (error) => {
console.log(error);
})
}
}
Answer the question
In order to leave comments, you need to log in
Maybe it's more correct to make a selection on the server, why pull the entire list of products?
But if there is not much data, you can filter:
var selectProducts = product.filter(function(category_id) {
return category_id === this.selectCategory_id
})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question