[Vuejs]-Access a state property within a getter

3👍

Please follow the guide to add vuex to your project : https://vuex.vuejs.org/guide/

You can add this where your Vue initiated, like this

import Vuex from 'vuex';

Vue.use(Vuex);

const store = new Vuex.Store({
    state: {
      message: "Hello from vuex",
      count: 0
    },
    mutations: {},
    actions: {},
    getters: {
      messageUpperCase: state => {
        // return state.message.toUpperCase();
        return state.message.toUpperCase()
      }
    }
})

And include while initiating the Vue like this

new Vue({
    el: '#your-id',
    store,
    render: h => h(App)
});

Answer to your question:

messageUpperCase: state => {
  // return state.message.toUpperCase();
  return state.message.toUpperCase()
}
👤Rijosh

Leave a comment