vue开发后台管理项目,登录后,请求数据每次session都不一致,后台返回未登录,处理方法打开main.js设置
import Vue from 'vue';
import axios from 'axios';
import App from './App.vue';
import router from './router';
import store from './store';
import dataV from '@jiaminghi/data-view';
import './plugins/element.js'
import './assets/css/global.css'
import './assets/icon/iconfont.css'
import 'element-ui/lib/theme-chalk/index.css'
import qs from 'qs'
import Lockr from 'lockr'
import dayjs from 'dayjs'
Vue.use(dataV);
// 按需引入vue-awesome图标
import Icon from 'vue-awesome/components/Icon';
import 'vue-awesome/icons/chart-bar.js';
import 'vue-awesome/icons/chart-area.js';
import 'vue-awesome/icons/chart-pie.js';
import 'vue-awesome/icons/chart-line.js';
import 'vue-awesome/icons/align-left.js';
// 全局注册图标
Vue.component('icon', Icon);
// 适配flex
import '@/common/flexible.js';
//引入bus
import bus from './views/bus.js';
Vue.use(bus);
// 引入全局css
import './assets/scss/style.scss';
import "./assets/scss/demo.scss";
import "./assets/scss/iconfont.scss";
//引入lodash
import _ from 'lodash'
Vue.prototype.$lodash = _
//设置请求路径
axios.defaults.baseURL="http://localhost:8899/vsm"
//意思是携带cookie信息,保持session的一致性
axios.defaults.withCredentials =true
//设置请求拦截
axios.interceptors.request.use(config=>{
//添加请求规则,怎么验证
config.headers['Authorization']=window.sessionStorage.getItem('token')
return config
})
Vue.prototype.$http=axios
Vue.prototype.qs=qs
Vue.prototype.$lockr=Lockr
Vue.prototype.$day = dayjs
Vue.prototype.$http=axios
//引入echart
import echarts from 'echarts'
Vue.prototype.$echarts = echarts
Vue.config.productionTip = false;
new Vue({
router,
store,
render: (h) => h(App),
}).$mount('#app');
withCredentials为false意思是不携带cookie信息,为保持session的一致性需设置为true;