-
Notifications
You must be signed in to change notification settings - Fork 381
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(fetch): add response method. #947
base: master
Are you sure you want to change the base?
Conversation
merge code.
merge code
merge code.
merge code
api实现方式不符合预期 |
packages/fetch/src/mock.js
Outdated
// custom不存在时,进行url参数匹配 | ||
const matched = (!test.custom) && doTest(configBackup, test).matched | ||
if (isFunction(callback) && ((isFunction(test.custom) && test.custom(configBackup)) || matched)) { | ||
let data = callback.call(config) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
访问config需要通过this访问吗?建议别这样设计,直接显式传参就尅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
是滴,那我修改成显式调用哈
packages/fetch/src/mock.js
Outdated
for (let item of options) { | ||
const { test, mock: callback } = item | ||
// custom不存在时,进行url参数匹配 | ||
const matched = (!test.custom) && doTest(configBackup, test).matched |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
把test.custom的处理也放在doTest中吧,外面就只需要调用doTest就可以,把proxy和validate中使用doTest的地方也修改一下
packages/fetch/src/xfetch.js
Outdated
@@ -81,6 +83,24 @@ export default class XFetch { | |||
} | |||
} | |||
|
|||
setMock (options) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
放到setProxy上面
处理冲突 |
1 similar comment
处理冲突 |
|
||
if (this.mockOptions) { | ||
let mockData = requestMock(this.mockOptions, config) | ||
if (isThenable(mockData)) return mockData |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mockData不能直接返回,我们的返回需要和真实response保持一致的数据结构
|
||
if (this.mockOptions) { | ||
let mockData = requestMock(this.mockOptions, config) | ||
if (isThenable(mockData)) return mockData |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mockData不能直接返回,我们的返回需要和真实response保持一致的数据结构,以及需要处理跨平台差异(可调用目前已有的transformRes方法
No description provided.