main.js
1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import ElementUI from 'element-ui'
import Axios from 'axios'
import qs from 'qs'
import 'element-ui/lib/theme-chalk/index.css'
import './assets/font/iconfont.css'
import './assets/style/reset.css'
import '@/utils/rem.js'
import '@/utils/filters.js'
import Vant from 'vant'
import 'vant/lib/index.css'
Vue.config.productionTip = false
Axios.defaults.baseURL = '/api/'
Vue.prototype.$axios = Axios
Vue.prototype.$qs=qs
//添加请求拦截器,在请求头中加token
Axios.interceptors.request.use(function (config) {
// 在发送请求之前做些什么
// config=>{
config.headers = {
'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
}
// if(localStorage.getItem('Authorization')){
// config.headers = {
// 'Authorization': localstorage.getItem('Authorization')
// }
// }
// }
return config;
}, function (error) {
// 对请求错误做些什么
return Promise.reject(error)
})
//添加响应拦截器
Axios.interceptors.response.use(function(response){
return response
},function(erros){
return Promise.reject(error)
})
Vue.use(ElementUI)
Vue.use(Vant)
new Vue({
router,
store,
render: h => h(App)
}).$mount('#app')