简体   繁体   English

为什么在我的 nuxt 页面中看不到后端的道具?

[英]Why I can't see my props from backend in my nuxt page?

I'm making an index page nad I have to recover from my db customers data and insert it in a table element in my index page.我正在制作一个索引页面,我必须从我的数据库客户数据中恢复并将其插入到我的索引页面的表元素中。 I've set my props, mounted function with axios that get the data from the backend route and in a data function I return customers array,我已经设置了我的道具,使用 axios 的安装函数从后端路由获取数据,并在数据函数中返回客户数组,

my index.vue page:我的 index.vue 页面:

<template>
  <div>
     <table v-if="customers">
  <tr>
    <th>name</th>
    <th>address</th>
  </tr>
  <tr>
    <td>{{ customers.name }}</td>
    <td>{{ customers.address }}</td>
  </tr>
</table>
  </div>
</template>

<script>
import Table from "../components/Table.vue";
export default {
  components: { Table },
  name: "IndexPage",
  data() {
    return {
      customers: [],
    };
  },
  props: {
    customer: {
      required: true,
      type: Object,
    },
  },
  async mounted() {
    const response = await this.$axios.$get("/api/customers");
    this.customers = response.data;
  },
};
</script>

if I write {{ customers }} the function return the list of customers fields but when I search for a specific data (for example {{ customers.name }}) it don't return me nothing, even errors.如果我写 {{ customers }} 该函数返回客户字段列表,但是当我搜索特定数据(例如 {{ customers.name }})时,它不会返回任何内容,甚至是错误。

Obviously I've set baseurl in nuxt.config with address of my laravel app显然我已经在 nuxt.config 中使用我的 laravel 应用程序的地址设置了 baseurl

Here you bring the data of all customers in the form of an array, If the data exists in the response, try using a v-for loop to iterate through the customers' array and display the data for each customer.在这里,您将所有客户的数据以数组的形式带入,如果数据存在于响应中,请尝试使用 v-for 循环遍历客户数组并显示每个客户的数据。 This would look something like this:这看起来像这样:

<template>
  <div>
     <table v-if="customers.length">
       <tr>
         <th>name</th>
         <th>address</th>
       </tr>
       <tr v-for="customer in customers" :key="customer.id">
         <td>{{ customer.name }}</td>
         <td>{{ customer.address }}</td>
       </tr>
     </table>
  </div>
</template>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM