我有 delete_task 操作,将任务ID发送到PHP文件以删除任务,虽然我正确触发了操作,但我在控制台中看到了效果但未删除任务,我尝试了很多很多次使用GET或POST或者只是将id静态地放在URL中但没有任何变化,任何人都可以帮我解决问题
tasksAction.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>
)
}
}
答案 0 :(得分:0)
在prev state
内的脱机对象中,它说online: false
吗?
如果是这样,并且您正在使用Android模拟器进行开发,则如果您使用的API级别低于25,则Wifi在模拟器上不可用,因此redux-offline认为您没有连接,因此不会发出初始网络请求
这是在iOS模拟器中测试redux-offline之后发生的,并且一切正常。
希望这会有所帮助。