https://blog.csdn.net/u012302552/article/details/79767288
在我實際寫的過程中,發現第一次點擊的時候並不會切換成英文,第二次點擊才行
故代碼更改如下
changeLangEvent () {
this.$confirm('確定切換語言嗎?', '提示', {
confirmButtonText: '確定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
if (this.lang === 'en-US') {
this.lang = 'zh-CN'
this.$i18n.locale = this.lang// 關鍵語句
} else {
this.lang = 'en-US'
this.$i18n.locale = this.lang// 關鍵語句
}
}).catch(() => {
this.$message({
type: 'info'
})
})
}