防止多个请求卡死

最有效简单的方法就是使用promise 进行步骤的请求

mounted () {

    const _this = this;
  getDictSpecialLabel().then((res)=>{
    _this.specialLabel = res;
    }).then(()=>{
return getDictRoleType().then((res)=>{
    _this.roleArr = res; 
    })
            }).then(()=>{
    return _this.getDetails();
    }).then(()=>{
    return _this.getProjectInfo();
    });

    }

http.js

export function getDictSpecialLabel(){
const _this = this
return new Promise((resolve, reject)=>{
//请求地址
axios.post(Config.url + 'sale/house/getDict/specialLabel')
.then((res)=>{
if(res.data.code === 200 && res.data.data && res.data.data.length > 0){
          let dicObj = {};
          const dicArr = res.data.data;
          dicArr.sort((a, b)=>(a.sort - b.sort));
          const specialColorArr = [
              "0,196,130", 
              "251,140,82", 
              "70,160,255", 
              "247,115,116", 
              "135,207,120"
            ];
            dicArr.map((item, index)=>{
           
            item.color = specialColorArr[index % 5];
           
              return item;
            });
            for (let i = 0; i < dicArr.length; i++ ){
            dicObj[dicArr[i].value] = dicArr[i];
          }
            resolve(dicObj)
        }
})

})
}





猜你喜欢

转载自blog.csdn.net/caoyan0829/article/details/80838429