数组对象排序:
vue:
compare(key) {
return function (obj1, obj2) {
const val1 = obj1[key];
const val2 = obj2[key];
if (val1 < val2) {
return -1;
} else if (val1 > val2) {
return 1;
} else {
return 0;
}
}
}
arr.sort(this.compare('id'))
网友评论