从indexeddb获取数据并将其显示在列表中

zdwk9cvp  于 2021-09-23  发布在  Java
关注(0)|答案(0)|浏览(182)

我试图从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;
    }

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题