Nuxtjs页面组件中属于父页面的未定义变量

时间:2019-01-30 11:02:33

标签: javascript vue.js vuejs2 nuxt.js

我有这两条路由/services/services/parents,并且每个页面被存储在vue文件是这样的:

//文件位置:“ / pages / services / index.vue”

<tr v-for="service in services" :key="service.id">
  <td class="check-col"><input type="checkbox"></td>
  <td class="number-col">{{ service.id }}</td>
  <td>{{ service.name }}</td>
  <td>{{ service.slug }}</td>
  <td>
    <template v-if="service.children.length">
      <template v-for="(child, index) in service.children">
        <nuxt-link :to="'/admin/services/' + child.id" :key="child.id">
          {{ child.name }}
        </nuxt-link>

        <span :key="child.id" v-if="(index+1) < service.children.length">, </span>
      </template>
    </template>

    <span v-else>--</span>
  </td>
</tr>

在我的/services/parents页面上,我有:

//文件位置:“ / pages / services / parents.vue”

<tr v-for="service in services" :key="service.id">
  <td>{{ service.id }}</td>
  <td>{{ service.name }}</td>
</tr>

<script>
export default{
  computed: {
    services() {
      return this.$store.getters['content-lists/services/list']
    }
  },
  async fetch({ store, query }) {
    let page = Number(query.page) || 1
    let perPage = Number(store.getters['content-lists/services/perPage'])
    let offset = (page - 1) * perPage

    const max = await strapi.request('get', '/services/count')
    store.commit('content-lists/services/setMaxPages', max)

    store.commit('content-lists/services/empty')
    const response = await strapi.request('post', '/graphql', {
      data: {
        query: `query {
          services(limit: ${perPage}, start: ${offset}) {
            id
            name
            slug
            children {
              id
              name
            }
          }
        }`
      }
    })

    response.data.services.forEach((service) => {
      store.commit('content-lists/services/add', {
        id: service.id || service._id,
        ...service
      })
    })
  }
}
</script>

当我导航到父页面时,它给了我这个错误:

  

service.children是未定义的

     

呈现页面时发生错误。检查开发者工具   控制台获取详细信息。

只有在使用<nuxt-link>导航时,如果您在浏览器地址中键入URL,它就可以正常工作。 我还检查了控制台,但没有痕迹,它只是说:Type error: service.children is not defined

我明白任何帮助预先

0 个答案:

没有答案