requestInterceptors.js 568 B

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