Skip to content

Commit 97261a2

Browse files
AysninePanJiaChen
authored andcommitted
fix[MockJS]: fix bug with withCredentials after using mockjs (#1194)
* 修复 Mock 导致请求丢失 Cookie 的问题 修复 Mock 导致 Cookie 丢失的问题,只有在 XHR.open() 周期时,自定义的 withCredentials 会被挂载,此时检查是否是未被拦截的 xhr,并挂载自定义的 withCredentials ,无则默认为 false
1 parent 0f7cf7e commit 97261a2

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/mock/index.js

+10
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@ import articleAPI from './article'
44
import remoteSearchAPI from './remoteSearch'
55
import transactionAPI from './transaction'
66

7+
// 修复在使用 MockJS 情况下,设置 withCredentials = true,且未被拦截的跨域请求丢失 Cookies 的问题
8+
// https://github.com/nuysoft/Mock/issues/300
9+
Mock.XHR.prototype.proxy_send = Mock.XHR.prototype.send
10+
Mock.XHR.prototype.send = function() {
11+
if (this.custom.xhr) {
12+
this.custom.xhr.withCredentials = this.withCredentials || false
13+
}
14+
this.proxy_send(...arguments)
15+
}
16+
717
// Mock.setup({
818
// timeout: '350-600'
919
// })

0 commit comments

Comments
 (0)