【发布时间】:2021-11-26 01:02:09
【问题描述】:
您好,我制作了自定义数据表组件,我的 Table.vue 文件如下所示:
<template>
<div>
<v-data-table
:headers="headers"
:items="items"
:search="search"
:loading="loading"
loading-text="Loading... Please wait"
dense
>
<template v-slot:top>
<v-toolbar dark flat dense>
<v-toolbar-title>{{ title }}</v-toolbar-title>
<v-spacer></v-spacer>
<v-text-field
v-model="search"
append-icon="mdi-magnify"
label="Search"
single-line
hide-details
></v-text-field>
<v-spacer></v-spacer>
</v-toolbar>
</template>
</v-data-table>
</div>
</template>
<script>
export default {
name: "Table",
props: [
"headers",
"items",
"title",
"itemsPerPage",
"loading",
],
data: function () {
return {
search: '',
}
},
methods: {
},
};
</script>
我就是这样使用它的:
<Table
:headers="headers"
:items="groups"
:loading="loading"
title="Baseny"
>
</Table>
一切都很好,但我想为每个输入添加带有操作的自定义列(每个输入都有不同的 ID)
通常没有自定义组件我这样写:
<v-data-table
:headers="headers"
:items="times"
:items-per-page="5"
:search="search"
:loading="loading"
loading-text="Ładowanie... Proszę czekać"
>
<template v-slot:top>
<v-toolbar dark flat dense>
<v-toolbar-title>Lista zajęć</v-toolbar-title>
<v-spacer></v-spacer>
<v-text-field
v-model="search"
append-icon="mdi-magnify"
label="Szukaj"
single-line
hide-details
></v-text-field>
<v-spacer></v-spacer>
<v-btn
color="primary"
:to="{ name: 'admin.times.create' }"
>
Dodaj zajęcie
</v-btn>
</v-toolbar>
</template>
<template v-slot:item.actions="{ item }">
<v-icon
small
class="mr-2"
@click="show(item)"
>
mdi-pool
</v-icon>
<v-icon
small
class="mr-2"
@click="edit(item)"
>
mdi-pencil
</v-icon>
</template>
</v-data-table>
我正在使用这个 v-slot:
<template v-slot:item.actions="{ item }">
<v-icon
small
class="mr-2"
@click="show(item)"
>
mdi-pool
</v-icon>
<v-icon
small
class="mr-2"
@click="edit(item)"
>
mdi-pencil
</v-icon>
</template>
但是当我编写自定义可重用表格组件时它不起作用,当我将这些行放入标签时。这个怎么做?
【问题讨论】:
标签: vue.js vue-component vuetify.js