computed: {
sortedArticles() {
return this.articleTop.slice().sort((a, b) => {
// 将字符串转换为整数
const numLikeA = parseInt(a.numlike, 10);
const numLikeB = parseInt(b.numlike, 10);
// 首先根据 numlike 降序排序
if (numLikeB < numLikeA) {
return -1; // 返回负数a在b之前
} else if (numLikeA < numLikeB) {
return 1;
} else {
// 如果 numlike 相同,则比较 numwatch,也应该是降序
const numWatchA = parseInt(a.numwatch, 10);
const numWatchB = parseInt(b.numwatch, 10);
return numWatchB - numWatchA; // 如果 b 的 numwatch 大,返回 -1 (b 在前)
}
});
}
},
method:{
fetchArticleTop() {
this.$request.get('/article/articleTop', {
}).then(response => {
if (response.code === '200' && response.data) {
this.articleTop = response.data; // 先更新articleTop
} else {
console.error('Failed to fetch articletop:', response.message);
}
});
},
}
09-21
1080
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
06-10
401
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
05-26