zycp-demo/src/main.js

47 lines
1.1 KiB
JavaScript

import Vue from 'vue'
import axios from 'axios'
import VueAxios from 'vue-axios'
import App from './App.vue'
import router from './router'
import VueDirectiveImagePreviewer from 'vue-directive-image-previewer'
import 'vue-directive-image-previewer/dist/assets/style.css'
Vue.use(VueDirectiveImagePreviewer)
// Vue.config.productionTip = false
Vue.prototype.host = 'https://ypzy.emingren.com'
Vue.prototype.HOME = '/api'
// 添加请求拦截器具
axios.interceptors.request.use(config => {
if (config.url != "/api/api/user/login-by-Phone" && config.url != "/api/api/common/send-sms-captcha" &&config.url !='/api/api/user/has-phone-user') {
if (!localStorage.token) {
router.replace('/login');
return config
} else {
config.headers.Authorization = "Bearer " + JSON.parse(localStorage.token)
}
}
return config
})
// 添加响应拦截器
axios.interceptors.response.use(response => {
// console.log(response);
let res = {}
res.status = response.status
res.data = response.data
return res;
}, function(err) {
return Promise.reject(err)
}
);
Vue.use(VueAxios, axios)
new Vue({
router,
render: h => h(App)
}).$mount('#app')