main.js
import t from './t';
Vue.prototype.$t = t;
getLang.js
import store from './store/index'
const langs = ['zh-CN', 'en']
const getLang = {
lang:store.state.lang,
langs
}
export default getLang;
t.js
import i18n from 'simplest-i18n';
import getLang from './getLang';
const t = i18n({
locale: getLang.lang, // 当前语言
locales: getLang.langs // 支持的语言列表
});
export default t;
.vue
<span>{{ $t("真实姓名", "Real Name") }}</span>