-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
请问fetch能拦截吗? #146
Comments
我尝试了在html里面引mock来拦截fetch但是确实拦不住,不知道是我代码的原因还是什么原因。 |
我这也是 fetch 拦截不了 跟楼上的代码基本相同 |
请求成功,但没数据返回 |
@JackieLs @peirancao @lincolin 我自己的看法是不需要拦截,我目前找到两种方式可以用,一种是直接让rap返回现成data数据(因为我配合rap用的),另外一种是让它返回模板自己require('mockjs'),然后eval一下这模板 最后Mock.mock(safeeval(data));不过确实拦截不了,我建议自己写个if分支就ok了 |
@que01 恩,现在也是放弃了拦截fetch的想法,因为这个fetch貌似属于浏览器内部行为。跟ajax对象不太一样,虽然内部还是个ajax,但是那个内部应该是js无法接触的地方了。感谢提供方法。 |
Service Worker 不仅可以拦截 Fetch API,还可以做 PWA(渐进式 Web App) —— |
貌似作者已经不维护了,下面是一个支持拦截 使用的话: npm install @zjffun/mockjs
|
可以的,把你的 mock 模版转换为 api 即可。 |
The text was updated successfully, but these errors were encountered: