方案:接下来优化可以通过路由导航预加载,先获取字典之后,在加载页面
router.js
// 预加载字典
export function preloadDictionary(dictClassCodeList) {
const pList = []
dictClassCodeList.forEach(dictClassCode => {
const p = getDicValueList(dictClassCode)
pList.push(p)
})
return Promise.all(pList)
}
// 预加载字典
router.beforeEach((to, from, next) => {
if(to.meta && to.meta.dictClassCodeList&& to.meta.dictClassCodeList.length > 0) {
preloadDictionary(to.meta.dictClassCodeList).then(res => {
next()
})
} else {
next()
}
})
总结:其实这里都可以规定直接预加载字典,到页面直接使用加载后的字典,注册个全局filters就行,根本不用上面那些,先都记录上,后期根据需求灵活应用吧