租房小程序前端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

15 lines
708 B

6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
  1. /**
  2. * 请求拦截
  3. * @param {Object} http
  4. */
  5. export const requestInterceptors = (vm) => {
  6. uni.$uv.http.interceptors.request.use((config) => { // 可使用async await 做异步操作
  7. // 初始化请求拦截器时,会执行此方法,此时data为undefined,赋予默认{}
  8. config.data = config.data || {}
  9. // 可以在此通过vm引用vuex中的变量,具体值在vm.$store.state中
  10. // console.log(vm.$store.state);
  11. config.header['X-Access-Token'] = uni.getStorageSync('token');
  12. config.header['Content-Type'] = 'application/x-www-form-urlencoded'
  13. return config
  14. }, (config) => // 可使用async await 做异步操作
  15. Promise.reject(config))
  16. }