How to return an Asynchronous Anonymous function

problem description

use the vue axios library to make http requests
in this request interceptor, axios.interceptors.request.use communicates with ios to obtain some mobile device information parameters, and finally initiates a request return config;
but return config, which communicates asynchronously with ios, has not been able to get the response of ios

.

related codes

axios.interceptors.request.use(config => {
    // ios 
    window.__nativeFn("js_getAllDeviceInfo", {
        // ios
        response: r => {
            config.data = Object.assign(config.data, r.data)
        }
    })
    return config

}, error => {
    return Promise.reject(error);
});

try 1. Use a timer to see whether the ios responds (if the requirement is not realized in the timer, you can"t return config, the callback function in the timer, and you don"t know how to return give him axios.interceptors.request.use)

axios.interceptors.request.use(config => {
    // ios 
    window.a = false
    window.__nativeFn("js_getAllDeviceInfo", {
        // ios
        response: r => {
            config.data = Object.assign(config.data, r.data)
            window.a = true
        }
    })
    var i = 0
    let SI = setInterval(() => {
        iPP
        // 5ios 
        if(5000 <= i) {
            clearInterval(SI)
        }
        if(window.a) {
            clearInterval(SI)
            return config
        }
    })

}, error => {
    return Promise.reject(error);
});

attempt 2 initiated 2 api requests using @ yuanxiaowa method. The second api request was not issued. The config that did not print is always the first request related information

.
return new Promise(resolve => {
   // ios 
   window.__nativeFn("js_getAllDeviceInfo", {
   // ios
   response: r => {
      config.data = Object.assign(config.data, r.data)
      console.log(config)
      resolve(config)
     }
   })
})

axios.interceptors.request.use(config => {
    return new Promise(resolve => {
        // ios 
        window.__nativeFn("js_getAllDeviceInfo", {
            // ios
            response: r => {
                config.data = Object.assign(config.data, r.data)
                resolve(config)
            }
        })
    })

}, error => {
    return Promise.reject(error);
});
Menu