Skip to content
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

mock不支持 fetch吗? #163

Open
wuchuguang opened this issue Nov 29, 2016 · 4 comments
Open

mock不支持 fetch吗? #163

wuchuguang opened this issue Nov 29, 2016 · 4 comments

Comments

@wuchuguang
Copy link

let mock = require('mockjs');
const url_get = config.apiHost+"";

mock.mock(url_get,'GET',{
'list|1-10': [{
'id|+1': 1
}]
});
fetch(url_get).then(resp=>{
console.log(resp.getJson());
})
fetch不被拦截?

@xiaoxiaosaohuo
Copy link

好像是不支持,只支持ajax.

@nickrogit
Copy link

不支持,可用robe-ajax

@chinesedfan
Copy link

可以试试parrot-mocker-web,支持xhr/jsonp/fetch

@zjffun
Copy link

zjffun commented Jun 15, 2019

貌似作者已经不维护了,下面是一个支持拦截 fetch 的版本 zjffun/Mock-support-intercept-fetch

使用的话:

npm install @zjffun/mockjs

fetch 的拦截还是比较好实现的,因为拦截后返回 resolve 为 response 对象(通过 Response - Web APIs | MDN 创建)的 promise 对象就行。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants