项目一些配置存储在数据库,
前端项目初始化时需要同步先获取基本配置,然后才能渲染其它组件。
http请求采用axios,但是axios不支持同步请求。
解决方案:
在获取配置接口采用async await
async function initConfig(){
let url='htttp://123.com/getConfig';
let params={
"token": 'erwerwerewrwer'
};
await axios.post(url,params).then((data)=>{})
}
然后 接口返回消息之后再初始化Vue
initConfig().then(()=>{
new Vue({
el: '#app',
router,
components: { App },
template: '<App/>'
})
})