Answer the question
In order to leave comments, you need to log in
How to "get" to the getter with such a store structure?
How to "get" to the getter with such a structure?
// sliders.js
import api from '../config/api/client'
// initial state
export const state = () => ({
info: {}
})
// getters
export const getters = {
newProducts(state) {
return state.info.newProducts
}
}
// actions
export const actions = {
getNewProductsSlider ({ commit }) {
return api.get('v1/mainpage-info').then(result => {
console.log('result', result.data.info.newProducts)
commit('setNewProductsSlider', result.data.info)
})
}
}
// mutations
export const mutations = {
setNewProductsSlider (state, data) {
state.newProductsSlider = data
}
}
computed:{
...mapGetters(['sliders/newProducts'])
},
Answer the question
In order to leave comments, you need to log in
This solution helped
computed: mapGetters({
newProducts: 'sliders/newProducts'
}),
created () {
this.$store.dispatch('sliders/getNewProductsSlider')
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question