Reputation: 3
I dispatch an action in vuex to fetch an array image urls binding to the swiper or carousel, but now I want to add a local static image to the array,how to write it?
How can I do in the store or any other method?
actions:{
getBanner({commit, state}){
axios(url).then(data =>{
commit('setImageArr',data)
})
}
}
mutations:{
setImageArr(state,arr){
state.arr = arr
}
}
Upvotes: 0
Views: 1161
Reputation: 1446
add a mutation:
actions:{
getBanner({commit, state}){
axios(url).then(data =>{
commit('setImageArr',data)
})
}
}
mutations:{
setImageArr(state,arr){
state.arr = arr
},
addImg ({arr},{url}) {
arr.push(url)
}
}
usage:
this.$store.commit('addImg',{url:'your img url'})
Upvotes: 1