webkws
webkws

Reputation: 3

how to import an local static image in vuex store

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

Answers (1)

jacky
jacky

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

Related Questions