How to execute some logic before each axios request is executed, and click OK before each axios request to execute the request

I added it like this. No, the request will not be executed.

service.interceptors.request.use(config => {
  if (getToken()) {
    config.headers["token"] = getToken() // token-- ["X-Token"]key 
  } else {
    console.log("token")
  }
  const role = store.state.permission.roleList.find(role => role.url === config.url && role.confirmFlag === _const.YES)
  console.log(role)
  if (true) {
    MessageBox("?", "", {
      confirmButtonText: "",
      cancelButtonText: "",
      type: "warning"
    }).then(() => {
      config.headers["confirmUser"] = "wcsconfirmuser"
      config.headers["confirmPwd"] = "123456"
      // Do something before request is sent
      return config
    })
  } else {
    return config
  }
}, error => {
  // Do something with request error
  console.log(error) // for debug
  Promise.reject(error)
})
Jun.22,2021

solved

with Promise
service.interceptors.request.use(config => {
  return new Promise((resolve) => {
    if (getToken()) {
      config.headers['token'] = getToken() // token-- ['X-Token']key 
    } else {
      console.log('token')
    }
    const role = store.state.permission.roleList.find(role => role.url === config.url && role.confirmFlag === _const.YES)
    console.log(role)
    if (true) {
      MessageBox('?', '', {
        confirmButtonText: '',
        cancelButtonText: '',
        type: 'warning'
      }).then(() => {
        config.headers['confirmUser'] = 'wcsconfirmuser'
        config.headers['confirmPwd'] = '123456'
        console.log(JSON.stringify(config.headers))
        // Do something before request is sent
        resolve(config)
      })
    } else {
      resolve(config)
    }
  })
}, error => {
  // Do something with request error
  console.log(error) // for debug
  Promise.reject(error)
})

service.interceptors.request.use(config => {
  if (getToken()) {
    config.headers['token'] = getToken() // token-- ['X-Token']key 
  } else {
    console.log('token')
  }
  const role = store.state.permission.roleList.find(role => role.url === config.url && role.confirmFlag === _const.YES)
  console.log(role)
  if (true) {
    return MessageBox('?', '', {
      confirmButtonText: '',
      cancelButtonText: '',
      type: 'warning'
    }).then(() => {
      config.headers['confirmUser'] = 'wcsconfirmuser'
      config.headers['confirmPwd'] = '123456'
      // Do something before request is sent
      return config
    })
  } else {
    return config
  }
}, error => {
  // Do something with request error
  console.log(error) // for debug
  Promise.reject(error)
})
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e4c144-4460f.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e4c144-4460f.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?