切换语言之后,刷新页面时,就会重置为 locale: null。
indexedDB 初始化放在 beforeEach 钩子里时,组件的加载会先于钩子执行,
调用 getLanguage 获取数据库设定时,就会报错: indexedDB.ts:83
Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'transaction')
function getLanguage () {
fetchLanguageApi().then((res: IResultOr) => {
const { success, result } = res
if (success) {
localeLang.value = result.name
store.dispatch('saveLanguage', result.name === 'cn' ? zhCn : zhEn)
}
})
}
getLanguage()