我试图从api或indexeddb获取数据,并在列表中显示数据,但这样,我的样式不正确。看来它看不懂我的风格。我能做什么?
这是我的代码,
我从api获取数据:
fetch('https://60d9a27eeec56d0017477951.mockapi.io/api/Dideban')
.then(response =>response.json())
.then(res =>{
res.forEach(data =>{
createUi(data)
})
}).catch(err =>{
if('indexedDB' in window){
dbName.customers.toArray()
.then(res =>{
res.forEach(data =>{
createUi(data)
})
})
}
})
function createUi(data){
let card =`
<div className="custom-control custom-checkbox">
<input type="checkbox" className="custom-control-input namad" />
<label className="custom-control-label" >
<h2 className="h6 mb-0">${data.title}</h2>
<small className="candle-color">${data.body}</small>
</label>
</div>
`;
let cardsContentElements = document.getElementById('products');
cardsContentElements.innerHTML += card;
}
暂无答案!
目前还没有任何答案,快来回答吧!