Async/await async problem

requirements: when the page is loaded, send two requests at the same time, the code is as follows:

        async initData(id){
            //
            let res1 = await getPathCategory(id);
            this.categoryList = res1.result.list;

            //
            let res2 = await getPathListData(id,this.category,this.pageSize,this.pageNo);
            if(res2.result.list.length>0){
                this.pathList = [...res2.result.list];
                this.loading = false;
            }
        },

question: when you enter the current page from the previous page, only the first requested data is obtained. When the current page is refreshed again, the data will come out together

Mar.04,2022

it is recommended to check the overall logic. It is unlikely that something will go wrong here


try the following. Both functions need to be executed:

let resAll = await Promise.all(getPathCategory(id), getPathListData(id,this.category,this.pageSize,this.pageNo));

Menu