let thisNewsId = null;function handleQueryNewsId loadingvalue = true; thisNewsId = formDatanewsId; consolelog-------thisNewsId-=- thisNewsId; getNewsPage newsId thisNewsId page 1 pageSize 10
给出的代码有一些语法和逻辑错误,以下是修正后的代码:
let thisNewsId = null;
function handleQueryNewsId() {
loading.value = true;
thisNewsId = formData.newsId;
console.log('-------thisNewsId-=-', thisNewsId);
getNewsPage({ newsId: thisNewsId, page: 1, pageSize: 10 })
.then((data) => {
console.log('查询newsid是否存在的查询getNewsPage---data---', data.rows);
const newsIds = data.rows.map(obj => obj.newsId);
console.log('newsids==', newsIds);
if (newsIds.includes(thisNewsId)) {
console.log('---------在--------------------');
} else {
console.log('--------------不在---------------');
}
console.log('--------------判断完毕---------------');
newsList.value = data.rows;
total.value = data.total;
})
.finally(() => {
loading.value = false;
});
}
修正后的代码使用了includes()方法来判断newsIds数组是否包含thisNewsId。如果包含,则打印"在",否则打印"不在"。
原文地址: https://www.cveoy.top/t/topic/jb9c 著作权归作者所有。请勿转载和采集!