方法
一、解决js文件配置多语言枚举值,项目编译后切换语言枚举值语言没切换问题
代码如下(示例):
- 问题:js文件配置多语言下拉框枚举值,项目编译后,切换到英文,然后进入页面查看,发现还是中文
- 原因:编译前读取的语言是中文,编译后切换到英文,不会触发重新编译
-
store中代码
// 路径 store -> modules -> dict.js import i18n from '@/i18n' const dataDic = { state: { // 车辆五码-变更来源 carTcp5ChangeSourceSelectList: [] }, mutations: { REFRESH_DICT (state) { state.carTcp5ChangeSourceSelectList = [ { value: '0', label: 'LVIP' }, { value: '1', label: 'MES' }, { value: '2', label: i18n.t('page.Diagnostic_apparatus') }, { value: '3', label: i18n.t('page.Positive_abnormal') } ] } } } export default dataDic
-
切换多语言枚举值
// 路径 views -> LayOut -> index.vue import { mapMutations } from 'vuex' export default { mounted () { this.refresh_DICT() }, methods: { ...mapMutations([ 'REFRESH_DICT' ]), refresh_DICT () { this.REFRESH_DICT() } } }
-
组件中使用
import { mapState } from 'vuex' export default { computed: { ...mapState({ carTcp5ChangeSourceSelectList: state => state.dict.carTcp5ChangeSourceSelectList }) } }
网友评论