N
N
nastya_zholudeva2018-07-18 18:51:41
Vue.js
nastya_zholudeva, 2018-07-18 18:51:41

How to "get" to the getter with such a store structure?

How to "get" to the getter with such a structure?
5b4f612088383663101791.png

// 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
  }
}

I tried like this
computed:{
      ...mapGetters(['sliders/newProducts'])
    },

But I get the error "Property or method "newProducts" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property."

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
nastya_zholudeva, 2018-07-18
@nastya_zholudeva

This solution helped

computed: mapGetters({
      newProducts: 'sliders/newProducts'
    }),
created () {
      this.$store.dispatch('sliders/getNewProductsSlider')
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question