Using Vue.t() inside a state of Vuex
See original GitHub issueHey guys! I’am trying the following code:
import Vue from 'vue'
export default {
task: {
status: [
{ id: 'pending', name: Vue.t('pending') },
{ id: 'done', name: 'Done' }
]
}
}
That is my state.js which is the state of my VUEX! When I try to use the Vue.t function I have the following error:
Uncaught TypeError: _vue2.default.t is not a function
My solution (which I don’t think it’s the best one also good for performance)
Let my state.js like that:
import Vue from 'vue'
export default {
task: {
status: [
{ id: 'pending', name: 'pending' },
{ id: 'done', name: 'done' }
]
}
}
And I’ve done the following getters (vuex getter)
import { map } from 'lodash'
import { trans } from 'utils/helpers/translation' // helper for Vue.t(string)
export const getTaskStatus = ({ task }) => map(task.status, (obj) => {
return { id: obj.id, name: trans(obj.name) }
})
Anyone knows how is the best way to make it work?
Issue Analytics
- State:
- Created 7 years ago
- Comments:19 (3 by maintainers)
Top Results From Across the Web
State - Vuex
Vuex uses a single state tree - that is, this single object contains all your application level state and serves as the "single...
Read more >Using kazupon/vue-i18n inside a state of Vuex - Stack Overflow
That is my state.js which is the state of my VUEX! When I try to use the Vue.t function I have the following...
Read more >How To Manage State in a Vue.js Application with Vuex
In this application, you are going to iterate through this data to generate cards consisting of the name , abbreviation , city ,...
Read more >Managing Shared State In Vue 3 - Smashing Magazine
Additionally, Vuex does support development-time tools (via the Vue Tools) to work with the state management including a feature called time- ...
Read more >State Management in Vue 3 Applications with Vuex - Auth0
Learn how to manage state in Vue 3 Applications using Vuex. ... TL;DR: Shared data/state amongst components in front-end applications can ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
TL;DR: This worked for me:
this.$t('navigationLinkMain')
In the component’s file (e.g.: Component.vue):
In i18n.js file:
And in src/main.js:
I have tried the other options as my store is imported from the other file. I always got an error message (
_vue2.default.t is not a function
) when I calledVue.t
in/store.js
. TheVue
instances are not the same in different files, are they? Thank you @tvanier anyway.