requestInterceptors.js 593 B

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