久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

解決vue項(xiàng)目axios每次請(qǐng)求session不一致的問(wèn)題

瀏覽:7日期:2022-11-13 08:18:12

1、vue開(kāi)發(fā)后臺(tái)管理項(xiàng)目,登錄后,請(qǐng)求數(shù)據(jù)每次session都不一致,后臺(tái)返回未登錄,處理方法打開(kāi)main.js設(shè)置:

// The Vue build version to load with the `import` command// (runtime-only or standalone) has been set in webpack.base.conf with an alias.import Vue from ’vue’import App from ’./App’import router from ’./router’require(’es6-promise’).polyfill()import MintUI from ’mint-ui’import ’mint-ui/lib/style.css’import ElementUI from ’element-ui’;import ’element-ui/lib/theme-chalk/index.css’;import store from ’./store’import axios from ’axios’ // 1、在這里引入axios axios.interceptors.response.use(function(res) { var res = res.data; if(res.status === 403 ) { router.push(’/’) return res; } return res;}, function(error) { return Promise.reject(error);});axios.defaults.withCredentials = true; //意思是攜帶cookie信息,保持session的一致性Vue.prototype.$axios = axiosVue.prototype.stringify = require(’qs’).stringify; Vue.use(MintUI)Vue.use(ElementUI);Vue.config.productionTip = false /* eslint-disable no-new */new Vue({ el: ’#app’, router, store, components: { App }, template: ’<App/>’})

withCredentials為false意思是不攜帶cookie信息,為保持session的一致性需設(shè)置為true;

2、為解決跨域,需要代理

解決vue項(xiàng)目axios每次請(qǐng)求session不一致的問(wèn)題

3、數(shù)據(jù)請(qǐng)求

解決vue項(xiàng)目axios每次請(qǐng)求session不一致的問(wèn)題

補(bǔ)充知識(shí):解決跨域造成Vue-element每次請(qǐng)求sessionID不同問(wèn)題

vue-element作為前端開(kāi)發(fā)框架, 前后端分離項(xiàng)目ajax跨域, 每次http請(qǐng)求后sessionId均會(huì)發(fā)生變化,導(dǎo)致獲取session失敗,

只需要在文件vue-element-admin-master-1srcutilsrequest.js中添加如下代碼即可:

withCredentials: true,

crossDomain: true

整個(gè)axios請(qǐng)求為:

const service = axios.create({ baseURL: process.env.BASE_API, // api的base_url timeout: 5000, // request timeout withCredentials: true, crossDomain: true})

以上這篇解決vue項(xiàng)目axios每次請(qǐng)求session不一致的問(wèn)題就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持好吧啦網(wǎng)。

標(biāo)簽: IOS
相關(guān)文章:
主站蜘蛛池模板: 商城县| 泌阳县| 兰考县| 蛟河市| 长寿区| 汉阴县| 桐梓县| 清远市| 宁陵县| 溧水县| 商洛市| 滨海县| 买车| 淅川县| 湾仔区| 龙山县| 呼伦贝尔市| 静宁县| 宁都县| 津市市| 景泰县| 九龙城区| 永济市| 仙游县| 册亨县| 南投县| 沙坪坝区| 达孜县| 巫山县| 滨海县| 灵寿县| 类乌齐县| 澄江县| 萨迦县| 建始县| 晋中市| 安阳市| 松桃| 襄城县| 莎车县| 栖霞市|