我正在尝试将 (+) 图标添加到 v-datatable 中的标题列之一。下面的代码没有添加任何图标。实际上,为标头创建模板槽对数据表没有任何影响。
我尝试的,
<template>
<v-data-table
item-key="name"
:items="complainantInfos"
:headers="headers"
sort-by="Id"
class="elevation-1">
<template v-slot:top>
<v-toolbar flat color="white">
<v-toolbar-title>Inspection</v-toolbar-title>
<v-spacer></v-spacer>
</v-toolbar>
</template>
<template slot="headers" slot-scope="props">
<tr>
<th
v-for="header in props.headers"
:key="header.text">
<v-icon small >plus-circle-outline</v-icon>
{{ header.text }}
</th>
</tr>
</template>
</v-data-table>
</template>
<script>
import { mapGetters } from "vuex";
export default {
data(){
return{
complainantInfos:[
{
...
}
],
headers: [
{ text: 'NameSurname', value: 'name', align: 'left' ,width: "25%" },
{ text: 'ID', value: 'PersonelIdNumber' },
{ text: 'Phone-1', value: 'Cellular1' },
{ text: 'Phone-2', value: 'Cellular2' },
{ text: 'Work Phone', value: 'WorkPhone' },
{ text: 'InterPhone', value: 'Interphone' },
{ text: 'Email', value: 'Email' },
//{ text: '+', value: 'action', sortable: false, align: 'right'}
],
Run Code Online (Sandbox Code Playgroud)
我根据评论编辑了代码。问题解决了。
...
</v-card>
</v-form>
</v-dialog>
</v-toolbar>
</template>
<template v-slot:header.Actions="{ header }">
<v-icon small>plus-circle-outline</v-icon>{{ header.text }}
</template>
...
Run Code Online (Sandbox Code Playgroud)
由于您只想将图标添加到一个特定列,因此我建议header.columnName。
你的插槽看起来像这样:
<template v-slot:header.name="{ header }">
<v-icon small>plus-circle-outline</v-icon>{{ header.text }}
</template>
Run Code Online (Sandbox Code Playgroud)
如果列名称为“Cellular1”,则代码将为<template v-slot:header.Cellular1="{ header }">
。
请确保您已包含图标集。否则,不会为 呈现任何 HTML v-icon
。您可以使用默认的 mdi 图标进行测试,例如mdi-minus
。
归档时间: |
|
查看次数: |
5483 次 |
最近记录: |