for循环axios套axios调用,同步调取

1.function getsdd(){}事件

async/await把异步进行设置成同步进行

         var url = '/api/runtime/form/save';
                function checkAdult(asbdata) {
                    return asbdata.Date1617275438563 == "--";
                }
                var asb=data.filter(checkAdult);
//操作
async function getsdd(){
            for(var i=0;i<asb.length;i++){
                var ngs=asb[i].ShortText1613977221120;
                var ids=asb[i].id;
//操作
await axios.post("/api/runtime/query/list", { "filters":[ { "propertyCode": "ShortText1610415960253", "propertyType": 0, "propertyValue": ngs, "propertyValueName": ""} ], "mobile": false, "page": 0, "queryCode""ht001", "schemaCode": "ht001", "size": 1000 },{headers:{ "access_token":localStorage.getItem('token') } }).then(res => { if(res.data.content.length>0){ var params={ "bizObject":{ "data":{ "Date1617275438563":res.data.content[0].data.Date1617277223437, }, "id":ids, "schemaCode": "KHZDHZB2", "sheetCode": "KHZDHZB", "workflowInstanceId": "" }, "workItemId": "", "workflowCode": "", "workflowInstanceId": "" } axios({ url:url, method:'post', data:params }).then(res=>{ console.log(res,''); }) } }); } } getsdd();//调用函数

2.第二种事件方式

      var btn1=document.querySelector('.btn1');
                
       btn1.onclick= async function(){
                    var tct=document.querySelector('.abox-list2 input').value;
                    if(tct!=''){
                        var tims=tct.split('-')[0]+tct.split('-')[1];
                        for(var i=0;i<arr.length;i++){
                            for(var b=0;b<1;b++){    
                           await axios.post("/api/runtime/query/list", {"filters":[]},{headers:{"access_token":localStorage.getItem('token')}
                             }).then(res=>{
                                 axios.post(url,params).then(res => {
                                    console.log(res,'成功添加');
                                    // tab.style.display='none';
                                    abcbox.remove();//全部删除
                                 });
                               })
}

 

3.vue methods方法里的方式

async methodName(params){
  let isSuccess = false;
  await this.$http({
    url: URL,
    method: "get",
    params: this.$http.adornParams({
      params:params
    })
  }).then(({ data }) => {
    if (data && data.code === 0) {
      if(data.exist == 0){
        isSuccess = true
      }
    }
  }).catch(err => {
    console.log(err);
    this.$message({
      type: "error",
      message: "系统异常"
    });
  });
  return isSuccess
}

 

posted @ 2021-04-02 12:19  喜欢美食的利亚  阅读(1728)  评论(0编辑  收藏  举报