diff --git a/package.json b/package.json index 942ef8f1..367d6c96 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "d2-admin", - "version": "1.5.2", + "version": "1.5.3", "private": true, "scripts": { "serve": "vue-cli-service serve --open", diff --git a/src/mock/index.js b/src/mock/index.js index 86af00fa..0a81b2cf 100644 --- a/src/mock/index.js +++ b/src/mock/index.js @@ -1,5 +1,10 @@ import Mock from 'mockjs' +// 补丁 解决 mock.js 影响 Cookie 携带 +import PatchCookie from './patch/cookie' + +PatchCookie(Mock) + // 导入所有的接口 const req = context => context.keys().map(context) req(require.context('./api/', true, /\.js$/)) diff --git a/src/mock/patch/cookie/index.js b/src/mock/patch/cookie/index.js new file mode 100644 index 00000000..0c101283 --- /dev/null +++ b/src/mock/patch/cookie/index.js @@ -0,0 +1,10 @@ +export default function (Mock) { + // 解决 Mock 情况下,携带 withCredentials = true,且未被拦截的跨域请求丢失 Cookies 的问题 + Mock.XHR.prototype.proxy_send = Mock.XHR.prototype.send + Mock.XHR.prototype.send = function () { + if (this.custom.xhr) { + this.custom.xhr.withCredentials = this.withCredentials || false + } + this.proxy_send(...arguments) + } +}