如何将图标添加到 vuetify DataTable 中的 Header

How to add icon to the Header in vuetify DataTable

我正在尝试将 (+) 图标添加到 v-datatable 中的 header 列之一。 下面的代码没有添加任何图标。实际上,为 header 创建模板插槽对数据表没有任何影响。

我试过的,

<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'}
              
            ],   

我已经根据评论编辑了代码。问题解决了。

 ...

    </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>
...

由于您只想将图标添加到一个特定的列,我建议 header.columnName

您的广告位将如下所示:

<template v-slot:header.name="{ header }">
  <v-icon small>plus-circle-outline</v-icon>{{ header.text }}
</template>

如果列名称为“Cellular1”,代码将为 <template v-slot:header.Cellular1="{ header }">

请确保您已包含图标集。否则,不会为 v-icon 呈现 HTML。您可以使用默认的 mdi 图标对其进行测试,例如 mdi-minus.