【问题标题】:SSR error when Writing API in Nuxt with Router Module?使用路由器模块在 Nuxt 中编写 API 时出现 SSR 错误?
【发布时间】:2018-04-23 12:25:36
【问题描述】:

我将 Nuxt 与路由器模块一起使用 目前,我这样写api:

<template>
  <div class="row flex">
    {{posts.id}}
  </div>
</template>
<script>
  import axios from 'axios'
  import Item from '~/components/feeds/Post.vue'
  export default {
    async asyncData ({ store, route }) {
      let { data } = await axios.get('http://localhost:8000/api/v1/feeds/' + route.params.id + '/')
      return {
        posts: data
      }
    },
    components: {
      'post-detail': Item
    }
  }
</script>

我收到此错误: 我该如何解决这个问题。

【问题讨论】:

    标签: vue.js vuejs2 vue-router nuxt.js


    【解决方案1】:

    也许它可以以某种方式帮助你。

    export default {
            layout: 'main',
            async asyncData ({store, params}) {
                let projectId = params.id;
                let {data} = await axios.get('https://admin.xxx.com/page/preview/' + projectId)
                return {
                    pageContent: data.xxx,
                    title: data.xxx.meta_title,
                    description: data.xxx.meta_desc,
                    keywords: data.xxx.meta_key,
    
                }
            },
    }
    

    【讨论】:

    • 那么也许应该是评论
    猜你喜欢
    • 1970-01-01
    • 2021-11-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-01
    • 2022-06-15
    相关资源
    最近更新 更多