Merge branch 'hotfix/mock_cookie'
Former-commit-id: e3b6e3f98c825c3d63460703017d097994d2d61b [formerly e3b6e3f98c825c3d63460703017d097994d2d61b [formerly e3b6e3f98c825c3d63460703017d097994d2d61b [formerly e3b6e3f98c825c3d63460703017d097994d2d61b [formerly 3d262d79eebc2b80c862bbd85432e22d63867927 [formerly 06b5b3f5027f43604eec3049e7aec2db3d76fea7]]]]] Former-commit-id: 9cef203e38b6680f404b9cbbafe4fd5599129054 Former-commit-id: 9eda3f70b6ea8fa9f5e93c172b9a64e6f2a33270 Former-commit-id: f7bebd4c17a07aa1ac7a885bbbb4e5c60aa4c134 [formerly c556dcda1c3eb1bf7d67f1780becfa8fcdab8497] Former-commit-id: 9dd7df8fb8757eae50b5e36df48fc99eaae4e7f4 Former-commit-id: ff5ff1b336886c7980e4af13590e0314c366221d Former-commit-id: 88276bcf7ae6f297b2e4dcf977fb121c58c80c78 Former-commit-id: f68f0dd8f28dbb09e58c0e1c9fad2466e34357e9 Former-commit-id: de5f6b5a3b1aa482e7712aa852902913f33345e2
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "d2-admin",
|
||||
"version": "1.5.2",
|
||||
"version": "1.5.3",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"serve": "vue-cli-service serve --open",
|
||||
|
||||
@@ -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$/))
|
||||
|
||||
10
src/mock/patch/cookie/index.js
Normal file
10
src/mock/patch/cookie/index.js
Normal file
@@ -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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user