【发布时间】:2021-06-12 04:14:07
【问题描述】:
我在表格中显示数据时遇到问题。当我尝试将道具发送到我的表格组件时,一切正常,来自https://jsonplaceholder.typicode.com/users 的数据显示完美(例如姓名、电子邮件)但是如果数据中有一个对象(例如 company.name),则数组不会显示该元素.
这是我的 Axios 请求,带有 TH 元素的 configList 和发送的 props
<template>
<section>
<header>
<h1></h1>
</header>
<main class="container">
<Table :config="configList" :dataTable="usersList"/>
</main>
</section>
</template>
<script>
import Table from "@/components/Table.vue"
export default {
components: {
Table
},
data() {
return {
usersList: null,
configList: [
{
key: "name",
name: "Imię i nazwisko",
},
{
key: `email`,
name: "E-mail",
},
{
key: `company.name`,
name: "Nazwa firmy",
},
{
key: "address.city",
name: "Miasto",
},
{
key: "website",
name: "Strona internetowa",
}
]
}
},
async mounted() {
const users = await this.$axios.$get("https://jsonplaceholder.typicode.com/users")
this.usersList = users
console.log(users[0].address.city)
}
}
</script>
这里,我的表格组件
<template>
<table>
<thead>
<tr>
<th v-for="(item, id) in config" :key="id">
{{ item.name }}
</th>
</tr>
</thead>
<tbody>
<tr v-for="(row, id) in dataTable" :key="id">
<td v-for="(item, id) in config" :key="id">
{{ row[item.key] }}
</td>
</tr>
</tbody>
</table>
</template>
<script>
export default {
props: ["config", "dataTable"],
}
</script>
我不知道如何显示 company.name 和 address.city。姓名、电子邮件或网站等简单数据运行良好。
【问题讨论】:
标签: javascript vue.js vuejs2 vue-component nuxt.js