I am making a Vuejs post request when component is mounted (using Vuex actually), and it all looks good. But when I inspect the console under network tab, I see that the get
request is actually sent to the backend multiple times when the page loads. Is this normal? This is my request (using axios)
// component calling Store action
methods: {
...mapActions({
fetchItems: 'items/fetchCart'
}),
},
mounted(){
this.fetchItems();
}
Now in Axios, this is the action sent to the backend
const actions = {
fetchItems({commit}){
return axios.get('/api/items').then((response) => {
// commit a mutation to set the items in the state
commit('SET_ITEMS', response.data)
}).catch((error) => {
console.log(error)
})
},
}
So this fetches the items just fine and populates the store, but I see from the network tab of my browser that this request is actually sent multiple times (5 times), which kind of affects some of my other logic in the backend.
I am using Laravel5.4
as the backend BTW.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire