learningMonk
learningMonk

Reputation: 1401

how to set object key/value pair to initial state in vuex

In my application, I am creating an object to store key/value pair for static texts and passing to the initial state. But, it is showing an error.

Here is my helpers.js:

    export const translation = Object.freeze({
        edit: 'Edit',
        please_select_text: 'Please select a row to edit',
        done: 'Done',
        role: 'Role',
});

Now I am importing this in my store module and passing like this:

const defaultState = () => ({
       localized: translation. // like that i am passing
  
});

In my component, I am using this state like this:

{{localized.edit}}



...mapState(module_name, ['localized']),

But, it is showing error. So, how can I use it properly for static texts?

Upvotes: 1

Views: 306

Answers (1)

maxshuty
maxshuty

Reputation: 10662

This doesn't seem like something that should live in your store as it's just a helper constant, not state.

In your component simply import translation from '@/path/helpers.js

Then use translation.edit.

Additionally if you did want it to live in your store then you're trying to use it as translation. instead of how it should be: translation. (Without the .)

Upvotes: 1

Related Questions