解决js文件配置多语言枚举值,项目编译后切换语言枚举值语言没切换

2023-03-01  本文已影响0人  瓩千瓦

方法

一、解决js文件配置多语言枚举值,项目编译后切换语言枚举值语言没切换问题

代码如下(示例):

  1. 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
    
    
  2. 切换多语言枚举值

    // 路径 views -> LayOut -> index.vue
    import { mapMutations } from 'vuex'
    
    export default {
        mounted () {
            this.refresh_DICT()
        },
        methods: {
            ...mapMutations([ 'REFRESH_DICT' ]),
            refresh_DICT () {
                this.REFRESH_DICT()
            }
        }
    }
    
    
  3. 组件中使用

    import { mapState } from 'vuex'
    
    export default {
        computed: {
            ...mapState({
                carTcp5ChangeSourceSelectList: state => state.dict.carTcp5ChangeSourceSelectList
            })
        }
    }
    
    
上一篇 下一篇

猜你喜欢

热点阅读