大家好,我试图创建一个 包含组件的新页面 当我启动npm run dev时,出现以下错误:
用户页面调用组件,借助vuetify UI组件,可以创建用户数据表
// pages / user.js
<template>
<div>
<datatable-component :data="data"></datatable-component>
</div>
</template>
<script>
import datatableComponent from "@/components/datatableComponent/index"
import UsersModel from "@/models/UserModel"
export default {
data () {
return {
data: UsersModel
}
},
components: {
datatableComponent,
}
}
</script>
我过去包含用户对象的数据,然后将其显示在数据表中
// components / datatbleComponent
export default {
name: 'datatable-component',
components: {},
props: ["data"],
data() {
return {
pagination: {
sortBy: 'id'
},
selected: [],
headers: this.data.headers,
items: this.data.data,
add_path: this.data.buttons.add_path
}
},
computed: {
},
mounted() {
},
methods: {
toggleAll() {
if (this.selected.length) this.selected = []
else this.selected = this.items.slice()
},
changeSort(column) {
if (this.pagination.sortBy === column) {
this.pagination.descending = !this.pagination.descending
} else {
this.pagination.sortBy = column
this.pagination.descending = false
}
}
}
}
如果您需要更多文件,请告诉我您需要什么,谢谢
// components / datatable / datatable.html
<section class="datatable-component">
<div>
<v-btn depressed color="#1867c0" dark right :href="add_path">
<v-icon dark>add</v-icon>
Add
</v-btn>
<v-data-table
v-model="selected"
:headers="headers"
:items="items"
:pagination.sync="pagination"
select-all
item-key="name"
class="elevation-1"
>
<template v-slot:headers="props">
<tr>
<th>
<v-checkbox
:input-value="props.all"
:indeterminate="props.indeterminate"
primary
hide-details
@click.stop="toggleAll"
></v-checkbox>
</th>
<th
v-for="header in props.headers"
:key="header.text"
:class="['column sortable', pagination.descending ? 'desc' : 'asc', header.value === pagination.sortBy ? 'active' : '']"
@click="changeSort(header.value)"
>
<v-icon small>arrow_upward</v-icon>
{{ header.text }}
</th>
</tr>
</template>
<template v-slot:items="props">
<tr :active="props.selected" @click="props.selected = !props.selected">
<td>
<v-checkbox
:input-value="props.selected"
primary
hide-details
></v-checkbox>
</v-layout>
</td>
<td>
<v-layout justify-center>
<v-btn depressed color="#ccc" light right small :href="props.item.actions[0].path + props.item.content[0].content" v-for="action in props.item.actions">
<v-icon small light>{{ action.icon }}</v-icon>
{{ action.test }}
</v-btn>
</v-layout>
</td>
<td v-for="item in props.item.content">
{{ item.content }}
</td>
</tr>
</template>
</v-data-table>
</div>
</section>
答案 0 :(得分:0)
出现错误消息后,问题可能是没有v-for
的{{1}},为了解决它,您可以使用数组中的属性或创建索引。
您应该在key
components/datatable/datatable.html
为此:
<td v-for="item in props.item.content">
{{ item.content }}
</td>
在其中创建到<td v-for="(item, index) in props.item.content" :key="index">
{{ item.content }}
</td>
的索引并将其用作v-for