-
Notifications
You must be signed in to change notification settings - Fork 26
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
react-native 拦截所有接口而非指定url #89
Labels
bug
Something isn't working
Comments
目前并不支持在 react-native 环境下使用。 |
如果要使用,可以本地起一个 node server,并在服务端构造 mock 数据 |
好的,谢谢解答。
…---- 回复的原邮件 ----
| 发件人 | ***@***.***> |
| 日期 | 2022年05月28日 12:06 |
| 收件人 | ***@***.***> |
| 抄送至 | ***@***.******@***.***> |
| 主题 | Re: [lavyun/better-mock] react-native 拦截所有接口而非指定url (Issue #89) |
如果要使用,可以本地起一个 node server,并在服务端构造 mock 数据
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
问题简述
应用后拦截了所有接口请求且获取不到数据,返回:
[ReferenceError: Property 'location' doesn't exist]或者[ReferenceError: Property 'location' doesn't exist]
复现步骤
1、这是我的mock,js
const Mock = require('better-mock');
const data = Mock.mock({
'list|6-10': [
() =>
Mock.mock({
course_name: '课程名称',
'course_desc|20-100': '*',
module_name: '模块',
'zsd_id|5-10': '1111',
'is_enable|1-2': true,
'degree|1-5': 1, // 难度
}),
],
});
console.log(data);
Mock.mock(/api/v4/course/catalogue/, 'post', option => {
console.log('mock---api/v4/course/catalogue请求参数', option);
return data;
});
2、这是我在根目录index.js的引用代码
// 引入mock
let mock = true;
if ((env === 'test' || env === 'dev') && mock) {
require('./mock');
}
3、这是我的接口调用(post是封装好的带naseUrl的axios请求)
function getCourseCatalogue({
user_id,
course_id,
class_id,
}: {
user_id: number;
course_id: number;
class_id: number;
}) {
return post('api/v4/course/catalogue', {user_id, course_id, class_id}, false);
}
期望有小伙伴能帮助解决~
The text was updated successfully, but these errors were encountered: