html - Vuetify <v-data-table> 自定义 <th> header

标签 html vue.js vuejs2 vuetify.js v-data-table

我正在使用 Vuetify <v-data-table> 。 如何在表格标题上添加按钮<th>

这段代码是我迄今为止尝试过的。

<v-data-table v-model="selected" :headers="headers" :items="desserts">
  <template slot="items" slot-scope="row">
    <th><button>button</button></th>
  </template>
</v-data-table>  

<script>
export default {
    data:() =>({
    headers: [
          {
            text: 'Dessert (100g serving)',
            align: 'start',
            sortable: true,
            value: 'name',
          },
          { text: 'Calories', value: 'calories' },
          { text: 'Fat (g)', value: 'fat' },
          { text: 'Carbs (g)', value: 'carbs' },
          { text: 'Protein (g)', value: 'protein' },
          { text: 'Iron (%)', value: 'iron' },
        ],
});
</script>

请帮忙。

最佳答案

您可以使用 header.<fieldname> 插槽模板。

例如,要定位第一列,name :

<v-data-table v-model="selected" :headers="headers" :items="desserts">

  <template v-slot:header.name="{ header }">
    {{ header.text }}
    <v-btn>Button</v-btn>
  </template>

</v-data-table>

关于html - Vuetify <v-data-table> 自定义 <th> header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66556681/

相关文章:

javascript - Vue.js + Webpack + vue-loader + bootstrap-sass + sass-loader

css - 无论如何要去除阴影,或强制 vuetify 菜单与屏幕左侧完全对齐?

javascript - 如何使用 vue-multiselect 的 v-model 值选中复选框

validation - 如何在 Vue 中将 min/max 属性应用于 v-model?

javascript - 在 vuejs 2 中将 prop 变成数据属性

javascript - 我们如何将 html 元素作为参数传递给 handlebar helper 以实现显示更多/更少的功能

html - 如何仅使用 CSS 将 Div 固定到页面顶部

javascript - Vuejs 应用程序未在 Chrome 扩展中呈现

电子邮件中的 HTML <base> 标记

javascript - 在 JavaScript 中使用来自 JSON 的数据动态填充表的快速方法