[技术分享]ES6 之 Dome-Fetch 请求与遍历

maoshiba发布于1 个月前 • 64 次阅读

<script>
    var i = document.getElementById("header")
    fetch("https://www.easy-mock.com/mock/5d2951ae92da6821fce72f31/list/list",
        {
            method: 'GET',
            headers: { 'Content-Type': 'application/json;charset=utf-8' }
        })
        .then(response => {
            return response.json();
        })
        .then(function (data) {
            // console.log(data.data.map(item => item.img));
            let cont = data.data.map(item => item.img);
            let e = [];
            let list = e = cont;
            // for (var i = 0; i < cont.length; i++) {
            //     e.push(cont[i].img);
            // }
            for (let item of list.entries()) {
                console.log(item);
            }
            for (let val of list) {
                console.log(val);
            }
        })
        .catch(function (err) {
            console.log("err");
        });
</script>
共收到 1 条回复
maoshiba

开心