When encapsulating a http request with axios, how to determine the corresponding operation after the custom status value is successful?

previously you could handle this in ajax

request(param){
    $.ajax{
        type: param.type,
        url: param.url,
        success(res){
            if(res.status === 0){
                typeof param.success === "function" && param.success(res.data)
            }else if(res.status === 1){
                login()        
            }else if(res.status === 2){
                typeof param.success === "function" && param.success(res.data)
            }
        },
        error(err){
            typeof param.error === "function" && param.error(res.err)
        }
    }
} 
   

in a case like the one above, for example, a status of 0 indicates success, and then the processing is performed after success. How do you deal with this in axios?

Apr.07,2021

import axios from 'axios'

//
axios.interceptors.request.use(function(config){
    ...
    return config
})

//
axios.interceptors.response.use(function(config){
    ...    
    return config
})
Menu