react-native - 为什么带有 react-native 的 redux-offline 不发送 POST 请求?
问题描述
我有delete_task操作,将任务 id 发布到 PHP 文件以删除任务,虽然我正确触发了操作并且我在控制台中看到了效果但任务没有被删除,我尝试了很多次使用 GET 或 POST 或只是把id 在 URL 中静态但没有任何变化,谁能帮我解决问题
任务Action.js
export const delete_task = id => ({
type: DELETE_TASK,
payload: {id},
meta: {
offline: {
// the network action to execute:
effect: { url: 'http://localhost/todos/remove.php', method: 'POST',body: {id} },
// action to dispatch when effect succeeds:
commit: { type: DELETE_SUCCESS, meta: { id } },
// action to dispatch if network action fails permanently:
rollback: { type: DELETE_FAILED, meta: { id } }
}
}
});
store.js
import React, { Component } from 'react';
import { applyMiddleware, createStore, compose } from 'redux';
import { offline } from '@redux-offline/redux-offline';
import offlineConfig from '@redux-offline/redux-offline/lib/defaults';
import {Provider} from 'react-redux';
import logger from 'redux-logger';
import RootNavigator from "./config/routes";
import reducers from './reducers'
// store
const middleware = [];
if(process.env.NODE_ENV === 'development'){
middleware.push(logger);
}
const store = createStore(
reducers,
undefined,
compose(
applyMiddleware(...middleware),
offline(offlineConfig)
)
);
export default class App extends Component {
render() {
return (
<Provider store={store}>
<RootNavigator />
</Provider>
)
}
}
解决方案
在离线对象里面prev state
,有没有说online: false
?
如果是这样,并且您正在 Android 模拟器中进行开发,如果您使用 API 级别 25 以下的模拟器,则 Wifi 在模拟器上不可用,因此 redux-offline 认为您没有连接并且不会发出初始网络请求。
在 iOS 模拟器中测试 redux-offline 并且一切正常后,这发生在我身上。
希望这可以帮助。
推荐阅读
- java - Android 富文本 Mark Down
- xml - 架构文件名未检测命名空间
- javascript - 如何在 ionic 中使用 jQuery 日期时间范围选择器
- .net - 通过 BotFramework 获取电报中的电话号码
- python - 如果变量不是 None 并且大于一行中的某个值,如何检查 python?
- linux - 如果路径不存在,请尝试其他路径
- python - “from .checks import *”和“from .import 检查”之间的区别
- cryptography - 我正在尝试解决 RSA 算法,我如何生成公钥?在数学问题中......我无法理解
- javascript - 如何在js中选择时将数据存储在内存中
- ios - 在使用 swift ios 的某些 URL 情况下,Alamofire 进度状态显示 0.0