export default function ({ app }) {
// onBeforeLanguageSwitch called right before setting a new locale
app.i18n.onBeforeLanguageSwitch = (oldLocale, newLocale, isInitialSetup, context) => {
console.log(oldLocale, newLocale, isInitialSetup)
}
// onLanguageSwitched called right after a new locale has been set
app.i18n.onLanguageSwitched = (oldLocale, newLocale) => {
console.log(oldLocale, newLocale)
}
}
1条答案
按热度按时间oyxsuwqo1#
您可以使用
onBeforeLanguageSwitch
回调函数。从官方文件来看
在切换应用的区域设置之前调用。可用于通过返回新的区域设置代码来重写新的区域设置。
所以你可以创建一个插件来处理你的逻辑。例如(在官方文档中):
/plugins/i18n.js
: