1234567891011121314151617181920212223242526272829 |
- import Cache from '../cache'
- import { getToken } from '../auth'
- /**
- * 请求拦截
- * @param {Object} http
- */
- module.exports = vm => {
- uni.$u.http.interceptors.request.use(
- config => { // 可使用async await 做异步操作
- config.data = config.data || {}
- const brandId = Cache.get('brand_id') ? Cache.get('brand_id') : 18
- if (brandId) {
- config.header['Brand-Id'] = brandId
- }
- if (Cache.get('store_id')) {
- config.header['Store-Id'] = Cache.get('store_id')
- }
- if (getToken()) {
- config.header['Authorization'] = getToken()
- }
- return config
- }, (config) => { // 可使用async await 做异步操作
- return Promise.reject(config)
- })
- }
|