I currently have a structure like /url/{category}
.
Below is the code snippet used to fetch and display some of these on the main page:
export default {
data() {
return {
topnews:[],
newsfive:[],
categories: {
tshirts:'',
shirts:'',
shoes:'',
useful:'',
}
}
},
methods() {
async getAll(){
axios.all([
axios.get(`/topnews`),
axios.get(`/news`),
axios.get(`/tshirts`),
axios.get(`/shirts`),
axios.get(`/shoes`),
axios.get(`/useful`)])
.then(axios.spread((topnews, news, tshirts, shirts, shoes, useful) => {
news.data.length = 5;
tshirts.data.length = 5
shirts.data.length = 5
shoes.data.length = 5
useful.data.length = 5
this.newsfive = news.data;
this.topnews = topnews.data;
this.categories = {
tshirts: tshirts.data,
shirts: shirts.data,
shoes: shoes.data,
useful: useful.data,
}
})).catch(error => console.log(error))
}
}
created() {
this.getAll()
}
}
The functionality works as intended. However, when changing the route to /tshirts
and navigating back to the main page using the browser, an error message is displayed:
typeerror content read-only property
In addition, I am looking for a way to streamline the rendering process by combining the different items into a single array instead of having separate div elements:
<div v-for="tshirts,key in categories.tshirts" :key="categories.tshirts.slug">
<img :src="tshirts.thumb" class="img-responsive" width=100%/>
<p>{{tshirts.title}}</p>
</div>
Is it feasible to create a filtered computed response from the axios call and then render a single div element for all items?
<div v-for="item,key in categories(tshirts)" :key="categories(item.slug)">
Additionally, how can I limit the size of the axios response array?