add:增加语言包依赖
This commit is contained in:
@@ -28,7 +28,7 @@
|
||||
</el-checkbox>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-dropdown style="display: flex; justify-content: right; color: #409EFF;" trigger="click" @command="langChange">
|
||||
<el-dropdown style="display: flex; justify-content: right; color: #409EFF;" trigger="click" @command="changeLanguage">
|
||||
<span class="el-dropdown-link">
|
||||
{{ language }}
|
||||
</span>
|
||||
@@ -108,6 +108,18 @@ export default {
|
||||
},
|
||||
methods: {
|
||||
// 中英文切换
|
||||
// 语言切换-x
|
||||
async changeLanguage(locale) {
|
||||
// 如果已经加载过该语言,可以直接设置,避免重复请求
|
||||
if (!this.$i18n.getLocaleMessage(locale)) {
|
||||
const messages = await fetchMessages(locale)
|
||||
this.$i18n.setLocaleMessage(locale, messages)
|
||||
}
|
||||
this.$i18n.locale = locale
|
||||
// 可以将当前语言保存到本地存储,以便下次使用
|
||||
localStorage.setItem('lang', locale)
|
||||
this.setLang(locale)
|
||||
},
|
||||
langChange(command) {
|
||||
this.$i18n.locale = command
|
||||
localStorage.setItem('lang', command)
|
||||
|
||||
Reference in New Issue
Block a user