requestInterceptors.js 455 B

1234567891011121314151617181920
  1. import { getToken } from '../auth'
  2. /**
  3. * 请求拦截
  4. * @param {Object} http
  5. */
  6. module.exports = vm => {
  7. uni.$u.http.interceptors.request.use(
  8. config => { // 可使用async await 做异步操作
  9. config.data = config.data || {}
  10. if (getToken()) {
  11. config.header['Authorization'] = getToken()
  12. }
  13. return config
  14. }, (config) => { // 可使用async await 做异步操作
  15. return Promise.reject(config)
  16. })
  17. }