axios 同步請求

項目一些配置存儲在數據庫,前端

前端項目初始化時須要同步先獲取基本配置,而後才能渲染其它組件。ios

http請求採用axios,可是axios不支持同步請求。數據庫

解決方案:axios

在獲取配置接口採用async await app

async function initConfig(){
    let url='htttp://123.com/getConfig';
    let params={
   "token": 'erwerwerewrwer'
   };
   await axios.post(url,params).then((data)=>{})

}async

而後 接口返回消息以後再初始化Vuepost

initConfig().then(()=>{
   new Vue({
    el: '#app',
    router,
    components: { App },
    template: '<App/>'
  })
})
相關文章
相關標籤/搜索