鍍金池/ 問(wèn)答/HTML5  HTML/ vue小白提問(wèn) axios怎么捕獲請(qǐng)求異常

vue小白提問(wèn) axios怎么捕獲請(qǐng)求異常

請(qǐng)問(wèn)各位大佬 這樣寫(xiě)規(guī)范么 有更好的建議么?
圖片描述

`
axios

                .post("/au/api/rulereleaseapply/findAllPubTask", {
                     branchCode: userInfor[0].branchCode,
                     userCode: userInfor[0].userCode,
                     busiinfoFive: "11"
                })
                .then(response => {
                    if (response.data.success) {
                      debugger;
                        console.log("審核數(shù)據(jù)=>", response.data);
                        _this.ruleReleaseVertifyData = response.data.entity.items;
                        loading.close();
                    } else {
                        loading.close();
                        this.$message({
                            showClose: true,
                            message: response.data.errorMessage,
                            type: "error"
                        });
                    }
                }).catch(response =>{
                  console.log('err',response);
                   loading.close();
                   loading.close();
                        this.$message({
                            showClose: true,
                            message: response.message,
                            type: "error"
                        });
                })

`

回答
編輯回答
孤慣

then 里面出現(xiàn)了語(yǔ)法錯(cuò)誤,拋出異常,也會(huì)走到 catch() 回調(diào)里面吧,不一定時(shí) 是 網(wǎng)絡(luò)錯(cuò)誤。

2017年8月9日 23:15
編輯回答
不二心

規(guī)范,但是可以用攔截器axios.interceptors.requestaxios.interceptors.response實(shí)現(xiàn),不然真的太累了。

提問(wèn)最好貼代碼而不是貼圖

2018年8月14日 01:15