JS異步請求

let myFunction = (page, form) => {
                    form.page = page
                    let promise = new Promise(function (resolve, reject) {
                        fetch_GET_NOT('/api_sic/000002.SZ', form).then((result) => {
                            let table = jsonTurn.json(result.data.data)
                            for (let x in table.data) {
                                that.table.data.push(table.data[x])
                            }
                            resolve(true);
                        }).catch(error => {
                            reject(error);
                        })
                    })
                    return promise
                }
                let waitGet = async (count, formData) => {
                    for (let i = 1; i < count; i++) {
                        await myFunction(i, formData)
                    }
                    setTimeout(() => {
                        INDEXdb.addData(that.table, window.location.pathname + 'tab');
                        that.autoHeight()
                    }, 1000)
                }
                fetch_GET('/api_sic/000002.SZ', that.selectForm).then((response) => {
                    if (response.data.status === 200) {
                        if (response.data.data !== '') {
                            console.log(response.data.totle_page)
                            that.table = jsonTurn.json(response.data.data)
                            waitGet(Math.round(response.data.totle_page), that.selectForm)

                        }
                    }
                })

在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章