requestInterceptors.js 636 B

12345678910111213141516171819202122232425
  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. config.header['Authorization'] = uni.getStorageSync('token')
  17. }
  18. return config
  19. }, (config) => { // 可使用async await 做异步操作
  20. console.log(config);
  21. return Promise.reject(config)
  22. })
  23. }