【发布时间】:2021-05-09 04:16:09
【问题描述】:
我需要使用稳定的方法在 VueJS 的单个组件中为两个表应用排序和分页逻辑。 目前我可以使用下面的链接对单个表格进行排序和分页。
https://www.raymondcamden.com/2018/02/08/building-table-sorting-and-pagination-in-vuejs
我的查询:
一个。对于字符串和数值的单个表,排序工作正常。但这里日期排序不起作用。
b.如果我需要为两个表应用两个计算数组,它工作正常。但是想确认我是否可以使用单个计算数组值来控制单个组件内的两个表。
“日期”排序问题的代码示例:
日期格式:日期:“27/01/2021”{此处为日期、月份、年份} 此处仅对前 2 位进行排序,因为排序不符合要求。
sortedCats:function() {
return this.cats.sort((a,b) => {
let modifier = 1;
if(this.currentSortDir === 'desc') modifier = -1;
if(a[this.currentSort] < b[this.currentSort]) return -1 * modifier;
if(a[this.currentSort] > b[this.currentSort]) return 1 * modifier;
return 0;
}).filter((row, index) => {
let start = (this.currentPage-1)*this.pageSize;
let end = this.currentPage*this.pageSize;
if(index >= start && index < end) return true;
});
}
请在这里帮助我。谢谢。
【问题讨论】:
标签: javascript node.js vue.js vuejs2 vue-component