【问题标题】:vuetify table custom sort "TypeError: Cannot read property 'filter' of undefined"vuetify 表自定义排序“TypeError:无法读取未定义的属性'过滤器'”
【发布时间】:2020-09-10 09:12:05
【问题描述】:

我在 vuetify 中的自定义排序实现存在问题。

      <v-data-table
        :headers="table.headers"
        :items="table.items"
        :search="search"
        disable-pagination
        :header-props="{sortByText: 'sortiere nach...'}"
        :loading="loading"
        hide-default-footer
        :custom-sort="customSort"
        @click:row="rowClickHandler"
      />

这是我现在的 customSort 函数

    customSort(items, sortBy, sortDesc, locale) {
      if (!this.table.loading) {
        console.log(items)
        console.log(sortBy)
        console.log(sortDesc)
        console.log(locale)
      }
    }

问题是我长胖了 Error in render: "TypeError: Cannot read property 'filter' of undefined" 也许这取决于我使用 axios 获取的异步数据?

我在我的created() 块中获取这样的内容

    async fetchUsers() {
      await axios
        .get('myApiPath')
        .then((res) => {
          this.table.items = res.data
          this.table.loading = false
        })
        .catch((err) => {
          console.log(err)
        })
    },

【问题讨论】:

    标签: vue.js axios vuetify.js


    【解决方案1】:

    您需要从您的customSort() 返回一个数组。我相信这与您的异步数据获取无关。

    customSort(items, sortBy, sortDesc, locale) {
      if (!this.table.loading) {
        console.log(items.map(e => e.calories));
        console.log(sortBy);
        console.log(sortDesc);
        console.log(locale);
      }
    
      // sort items here
    
      return items;
    }
    

    这是custom-sort() 中的sample implementation

    【讨论】:

      猜你喜欢
      • 2021-12-26
      • 2019-03-26
      • 2021-08-26
      • 2021-06-03
      • 2021-10-31
      • 2020-10-22
      • 2018-05-03
      • 1970-01-01
      • 2019-05-01
      相关资源
      最近更新 更多