Ant-design-vue 默认组件多语言切换

创建一个store对象,保存当前的语言

//默认语言
const langKey = "LocalLang";
export default {
  namespaced: true,
  state: {
    //默认中文
    lang: "",
  },
  mutations: {
    //初始化默认语言
    initLanguage(state) {
      var lang = localStorage.getItem(langKey);
      if (lang == null) {
        state.lang = "CN";
      }
      else {
        state.lang = lang;
      }
    },
    //切换语言
    setLanguage(state, lang) {
      state.lang = lang;
      localStorage.setItem(langKey, lang);
    }
  }
}

APPVUE里面,调用多语言设置






外部切换语言

changeLang(lang) {
      this.$store.commit("setting/setLanguage", lang);
      this.$message.success("切换成功");
    },

你可能感兴趣的:(VUE,vue.js,前端,typescript)