首页 > 解决方案 > Vuetify 数据表搜索不起作用

问题描述

我是 Vue 和 Vuetify 的新手。我在我的项目中使用 vuetify 数据表。除了搜索选项外,一切正常。我将所有内容都用作文档。但仍然没有得到任何解决方案。

作为基本要求,我使用这些代码添加搜索

模板

          <v-text-field
            v-model="search"
            append-icon="search"
            label="Search"
            single-line
            hide-details
          ></v-text-field>

         <v-data-table
          :headers="headers"
          :items="sales"
          :search="search"
          :rows-per-page-items="rowsPerPageItems"

          row
          wrap
          class="elevation-1"
        >

脚本

data(){
      return{
        search: '',
      }
  }  

这是完整的代码 https://github.com/Shakilzaman87/pukucrm/blob/master/src/components/sales/Sales.vue

标签: vue.jsvuetify.js

解决方案


Vuetify 应该在控制台中警告您:

[Vuetify] 标头必须具有与“v-data-table”中的 v-model 数组中的值对应的 value 属性

因此,您可以通过添加值来修复搜索选项:

headers: [
  { text: 'Item Name', value: 'item_name' },
  { text: 'Unit Price', value: 'price' },
  { text: 'Quantity', value: 'quantity' },
  { text: 'Customer', value: 'customer' },
  { text: 'Created', value: 'timestamp' },
  { text: 'Total', value: 'total' },
  { text: 'Action', value: 'item_name' }
]

(来自您的回购的数据)


推荐阅读