Node.js/nuxt/axios:修订间差异

来自康健生活
Kangkk​(留言 | 贡献)
Kangkk​(留言 | 贡献)
第32行: 第32行:
const bar= await getBar()</syntaxhighlight>
const bar= await getBar()</syntaxhighlight>


{{leftrightflex|<syntaxhighlight lang="javascript">
axios.all([
  axios.get('/v2/disease/footer_recommend'),
  axios.get('/v2/hospital/recommend/rand')
]).then(axios.spread(function(
  Disease_footer_recommend,
  HospitalRecommendRand
) {
  _self.Disease_footer_recommend = Disease_footer_recommend.data.data
  console.log(HospitalRecommendRand)
  _self.HospitalRecommendRand = HospitalRecommendRand.data.data
})).catch((error) => {
  console.log(error)
  _self.errorMessage = error
})
</syntaxhighlight>|{{consoleout|<pre>
</pre>}}}}
<syntaxhighlight lang="javascript">
<syntaxhighlight lang="javascript">
Promise.all([
Promise.all([
      $axios.get('/v2/home/menus'),
  axios.get('/v2/disease/footer_recommend'),
      ...
  axios.get('/v2/hospital/recommend/rand')
    ]).then(([ menuRes,...]) => {
]).then(([ Disease_footer_recommend, HospitalRecommendRand]) => {
      return {
  return {
        navMenus: menuRes.data.list,
    Disease_footer_recommend: Disease_footer_recommend.data.data,
        ...
    HospitalRecommendRand: HospitalRecommendRand.data.data
      }
  }
    })</syntaxhighlight>
})</syntaxhighlight>


或者自己封装
或者自己封装