zycp-demo/src/main.js

47 lines
1.1 KiB
JavaScript
Raw Normal View History

2022-03-03 03:28:10 +00:00
import Vue from 'vue'
2022-03-03 03:40:29 +00:00
import axios from 'axios'
import VueAxios from 'vue-axios'
2022-03-03 03:28:10 +00:00
import App from './App.vue'
import router from './router'
2022-03-04 12:25:37 +00:00
2022-03-18 12:35:34 +00:00
import VueDirectiveImagePreviewer from 'vue-directive-image-previewer'
import 'vue-directive-image-previewer/dist/assets/style.css'
Vue.use(VueDirectiveImagePreviewer)
2022-03-03 05:41:12 +00:00
// Vue.config.productionTip = false
2022-03-03 07:51:49 +00:00
Vue.prototype.host = 'https://ypzy.emingren.com'
2022-03-03 05:41:12 +00:00
Vue.prototype.HOME = '/api'
2022-03-07 11:31:43 +00:00
// 添加请求拦截器具
2022-03-03 05:41:12 +00:00
axios.interceptors.request.use(config => {
2022-03-08 11:35:09 +00:00
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') {
2022-03-09 10:24:18 +00:00
if (!localStorage.token) {
2022-03-07 11:31:43 +00:00
router.replace('/login');
return config
} else {
2022-03-09 10:24:18 +00:00
config.headers.Authorization = "Bearer " + JSON.parse(localStorage.token)
2022-03-07 11:31:43 +00:00
}
}
return config
})
2022-03-03 07:51:49 +00:00
2022-03-07 11:31:43 +00:00
// 添加响应拦截器
2022-03-08 11:35:09 +00:00
axios.interceptors.response.use(response => {
// console.log(response);
let res = {}
res.status = response.status
res.data = response.data
return res;
2022-03-09 07:04:38 +00:00
}, function(err) {
return Promise.reject(err)
}
);
2022-03-03 05:41:12 +00:00
2022-03-03 03:40:29 +00:00
Vue.use(VueAxios, axios)
2022-03-03 03:28:10 +00:00
new Vue({
2022-03-07 11:31:43 +00:00
router,
render: h => h(App)
2022-03-03 03:28:10 +00:00
}).$mount('#app')