mirror of
https://github.com/PanJiaChen/vue-element-admin.git
synced 2025-04-06 03:57:53 +08:00
* 修复 Mock 导致请求丢失 Cookie 的问题 修复 Mock 导致 Cookie 丢失的问题,只有在 XHR.open() 周期时,自定义的 withCredentials 会被挂载,此时检查是否是未被拦截的 xhr,并挂载自定义的 withCredentials ,无则默认为 false
40 lines
1.3 KiB
JavaScript
40 lines
1.3 KiB
JavaScript
import Mock from 'mockjs'
|
||
import loginAPI from './login'
|
||
import articleAPI from './article'
|
||
import remoteSearchAPI from './remoteSearch'
|
||
import transactionAPI from './transaction'
|
||
|
||
// 修复在使用 MockJS 情况下,设置 withCredentials = true,且未被拦截的跨域请求丢失 Cookies 的问题
|
||
// https://github.com/nuysoft/Mock/issues/300
|
||
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)
|
||
}
|
||
|
||
// Mock.setup({
|
||
// timeout: '350-600'
|
||
// })
|
||
|
||
// 登录相关
|
||
Mock.mock(/\/login\/login/, 'post', loginAPI.loginByUsername)
|
||
Mock.mock(/\/login\/logout/, 'post', loginAPI.logout)
|
||
Mock.mock(/\/user\/info\.*/, 'get', loginAPI.getUserInfo)
|
||
|
||
// 文章相关
|
||
Mock.mock(/\/article\/list/, 'get', articleAPI.getList)
|
||
Mock.mock(/\/article\/detail/, 'get', articleAPI.getArticle)
|
||
Mock.mock(/\/article\/pv/, 'get', articleAPI.getPv)
|
||
Mock.mock(/\/article\/create/, 'post', articleAPI.createArticle)
|
||
Mock.mock(/\/article\/update/, 'post', articleAPI.updateArticle)
|
||
|
||
// 搜索相关
|
||
Mock.mock(/\/search\/user/, 'get', remoteSearchAPI.searchUser)
|
||
|
||
// 账单相关
|
||
Mock.mock(/\/transaction\/list/, 'get', transactionAPI.getList)
|
||
|
||
export default Mock
|