问题描述
list2.forEach(item2 =>这行代码报错为
Uncaught (in promise) TypeError: list2.forEach is not a function
问题出现的环境背景及自己尝试过哪些方法
相关代码
function renderCnxh(list2 = []) {
// const item1 = list[0];
const jp3Warper = document.querySelector(".Wonderful--WonderfulBottom--e1G-ks7");
let cnxhHtml = "";
list2.forEach(item2 => {
cnxhHtml += `
<div class="rax-view-v2 Wonderful--WonderfulItem--22oI0pH"><a
href="https://detail.tmall.com/item.htm?scm=1007.12710.81708.110&id=642842719858&pvid=3837239a-bf11-4a67-852f-e82a169a09e1"><img
lazyload="true" quality="normal" data-once="true"
src="${item2.resultValue.resurt.data.imgUrl}"
data-before-current-y="821.796875" data-appeared="false" data-has-appeared="true"
data-has-disappeared="true" style="width: 220px; height: 220px; border-radius: 18px;">
<div class="Wonderful--mask--1fwB7tp"></div>
<p class="Wonderful--title--23U6SgE">${item2.resultValue.resurt.data.title}</p>
<p class="Wonderful--price--2VEZvrl">¥2699.0</p>
</a></div>
`
console.log(item2);
})
console.log(jp3Warper);
jp3Warper.innerHTML = cnxhHtml + jp3Warper.innerHTML;
}
ajaxPromise({
url: "http://localhost:9000/api/appkey"
}).then((res) => {
console.log(res);
renderCnxh(res.data);
});
你要确定你的res.data是不是一个数组,我估计是JSON字符串,是的话你得JSON.parse转一下