2025-03-26
This commit is contained in:
14
src/hooks/useDateSort.ts
Normal file
14
src/hooks/useDateSort.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
export const useDateSort = (property: any, bol: any) => {
|
||||
//property是你需要排序传入的key,bol为true时是升序,false为降序
|
||||
return function (a: any, b: any) {
|
||||
let value1 = a[property];
|
||||
let value2 = b[property];
|
||||
if (bol) {
|
||||
// 升序
|
||||
return Date.parse(value1) - Date.parse(value2);
|
||||
} else {
|
||||
// 降序
|
||||
return Date.parse(value2) - Date.parse(value1);
|
||||
}
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user