nuxt generate payload undefined

我的梦境 提交于 2021-02-10 21:16:11

问题


I have a Nuxt project, in nuxt.config.js file, I have a function like this:

generate: {
    async routes() {
      function postRoutes() {
        return axios
          .post('https://my-server.com/api/posts')
          .then((r) => r.data.map((post) => {
            // I log post data here, it exist
            console.log(post)
            return {
              route: `post/${post.id}`,
              payload: 'post'
            }
          }))
      }
      const response = await axios
        .all([postRoutes()])
        .then(function (results) {
          const merged = [].concat(...results)
          return merged
        })
      return response
    }
  },

Then, in pages/post/_slug.vue, in asyncData, when receiving payload object, it returns undefined

async asyncData({ params, error, payload }) { {
    console.log(payoad) // return undefined
}

I don't know whether I pass the payload the wrong way or something wrong with Nuxt payload, please help !! thank you in advance

来源:https://stackoverflow.com/questions/65739496/nuxt-generate-payload-undefined

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!