api/index.js
const URL = 'http://10.0.2.2:5000';
const fetching = false;
export default (type, filter, dateFilter, position) => {
if(fetching) return Promise.reject(new Error('Request in progress'));
fetching = true;
return fetch(URL + `/search/${type}/${filter}/${dateFilter}/${position}/0/0`)
.then(response => Promise.all([response, response.json()]))
.catch(err => console.log("error catch search:", err.message))
}
Run Code Online (Sandbox Code Playgroud)
我需要把 fetching 设为 false,这样我就可以再次调用这个函数,但我不知道把它放在哪里才能让它工作。如果我在 then writen 之后和 catch 之前创建另一个 then 像这样:
.then(() => fetching = false)
Run Code Online (Sandbox Code Playgroud)
问题是它返回 false 到调用函数的位置,而不是调用这里的数据:
动作/ index.js
getDataApi(type, filter, dateFilter, position)
.then(res => {
if (res !== false) {
if (state.dataReducer.data.length === 0) {
dispatch(getDataSuccess(res[1])) …Run Code Online (Sandbox Code Playgroud) 我在react-native run-android和另一个终端中执行项目,我这样做:
npm run react-devtools
它打开了一个新的电子窗口,上面写着:
react本机应用程序将在几秒钟内打开...
但什么也没发生。
我用Ctrl+ 放入模拟器切换检查器m,我可以在网络中看到它向它发出了请求,http://localhost:8097结果是它无法连接并继续尝试相同的结果。
打开的电子窗口说它正在等待与端口8097的连接,因此我可以看到正在尝试连接,但没有任何结果!
是否可以发布和订阅事件(如离子)以进行组件通信。我拥有的两个组件没有关联(没有父组件和子组件)。\n一个组件是一个带有按钮 Publish 的标题,另一个组件是一个表单。我想要的是将事件从单击的按钮发送到表单以进行验证,例如字段正文不能为空之类的内容。
\n\n编辑:\n我正在使用路由器通量。我的表单组件是NewPost,带有按钮发布的组件是ButtonsNewPost。该组件是父组件还是子组件?他们能以某种方式沟通吗?
\n\n <Scene\n key="newPost"\n component={NewPost}\n hideNavBar={false}\n renderRightButton={<ButtonsNewPost/>}\n navBarButtonColor=\'#fff\'\n >\nRun Code Online (Sandbox Code Playgroud)\n\n解决方案:
\n\nnewPost.js
\n\ncomponentWillReceiveProps(newProps) {\n let validationMessage;\n if(newProps.validationBody) {\n validationMessage = \'El campo descripci\xc3\xb3n es requerido\';\n this.showToastValidation(validationMessage);\n\n //without the next line the validation toast only appear once\n this.props.validation_body(false); \n } \n\n}\n\nconst mapStateToProps = state => {\n return {\n validationBody: state.validationBody\n }\n}\n\nconst mapDispatchToProps = dispatch => {\n return {\n validation_body: (validationBody) => \n dispatch(validation_body(validationBody))\n }\n}\n\nexport default connect(mapStateToProps, mapDispatchToProps)(NewPost)\nRun Code Online (Sandbox Code Playgroud)\n\n减速器/validationBody.js
\n\nexport default (state = false, …Run Code Online (Sandbox Code Playgroud) 这是我的代码:
properties.service.ts
get(stringParams) {
let headers = new Headers({
"X-AUTH-APIKEY": API_KEY
});
this.options = new RequestOptions({
headers: headers
});
return this.http
.get(`${API_URL}/properties/?${stringParams}`, this.options)
.timeout(50)
.map((response: Response) => response.json())
}
posts.ts
this.propertiesService.get(arrayParams).subscribe((data: any) => {
}), (err) => { console.log("timeoout")};
Run Code Online (Sandbox Code Playgroud)
我把50放在我的超时中因此被解雇但我无法以这种方式捕获错误
}), (err) => { console.log("timeoout")};
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
TimeoutError {name: "TimeoutError", stack: "TimeoutError: Timeout has occurred? at new Time…http://localhost:8100/build/polyfills.js:3:10143)", message: "Timeout has occurred"
Run Code Online (Sandbox Code Playgroud)
编辑:
this.propertiesService.get(arrayParams).subscribe((data: any) => {
}), (err) => { console.log("timeoout")};
get(stringParams) {
return this.http
.get(`${API_URL}/properties/?${stringParams}`, this.options)
.timeout(50)
.map((response: Response) …Run Code Online (Sandbox Code Playgroud)