vue.js - 为Vuetify数据表中的<td>和<tr>添加类?

标签 vue.js vuetify.js

 <v-data-table
      class="elevation-1 user-table"
      :headers="table.headers"
      :items="usersList"
      :items-per-page="table.options.itemsPerPage"
      :no-data-text="table.options.noDataText"
      :footer-props="table.options.footerProps"
    >
    <template slot="items" slot-scope="props">
        <td class="text-xs-right pa-4">{{ props.item.id }}</td>
        <td class="text-xs-right pa-0">{{ props.item.username }}</td>
        <td class="text-xs-right pa-0">{{ props.item.createdAt }}</td>
      </template> 
  
</v-data-table>

我尝试使用 slot="items"更改 vuetify 表中 td 的类,但它不起作用?

我使用这个版本的 vuetify

  • "vuetify": "^2.3.17",

最佳答案

将项目槽重构为此

<v-data-table
  class="elevation-1 user-table"
  :headers="table.headers"
  :items="usersList"
  :items-per-page="table.options.itemsPerPage"
  :no-data-text="table.options.noDataText"
  :footer-props="table.options.footerProps"
>
  <template v-slot:item="{ item }">
    <tr>
      <td class="text-xs-right pa-4"> {{ item.id }} </td>
      <td class="text-xs-right pa-0"> {{ item.username }} </td>
      <td class="text-xs-right pa-0"> {{ item.createdAt }} </td>
    </tr>
  </template>
</v-data-table>

你的代码有什么问题:

  1. 您使用了items而不是item => <template slot="item" slot-scope="props">
  2. 你错过了tr元素

关于vue.js - 为Vuetify数据表中的<td>和<tr>添加类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65229262/

相关文章:

vue.js - VueJS 方法和函数的区别?

vue.js - Vuex、vue-router 和处理页面重新加载 (F5)

vue.js - vuetify `v-tabs` 的子组件返回 offsetWidth 为 0

javascript - 如何更改 Vuetify 日历日期格式

javascript - 基于父组件中的 v-select 更改子组件中变量的值 (Vuetify)

javascript - 访问 Vue JS 实例监视对象中的 $refs 数组

vue.js - 如何将 Vuetify <v-card> 链接到外部网站?

node.js - SailsJs 中的全局函数

vue.js - 延迟加载组件不适用于 Vue Router

javascript - 如何在 vuetify 上安装翻译?