nuxt.js中使用fetch()请求数据

async fetch () {
    
    
    const webInfoData = await this.$api.home.getWebInfo()   //请求数据
    const companyInfoData = await this.$api.home.getCompanyInfo()  //请求数据
    this.$store.dispatch('home/setWebCompanyInfo', {
    
       //把数据存储进vuex中
      ...webInfoData.data.list[0],
      ...companyInfoData.data.list[0]
    })
  },

该生命周期可以在页面级组件和子组件中使用,内部可以访问到this
同时在服务端渲染。

Guess you like

Origin blog.csdn.net/qq_46634851/article/details/123187151