Vuetify 表自定义排序"TypeError: Cannot read property 'filter' of undefined"



我在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)
})
},

您需要从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()的示例实现。

最新更新