FetchAction
Quickly create AJAX action tool
install 安装
npm install fetch-action --save
Usage 使用
Basic, 基础使用
;; const API = ''; // Define actions, 定义操作 const GET_USER_OK = 'GET_USER_OK';const getUserOK = { return type: 'GET_USER_OK' payload: rst};const getUser = ; // Define reducer, 定义 reducerconst reducer = { }; // Generate data, 生成数据const user = ; // Perform the operation, 执行操作user;
redux-act, 使用 redux-act 简化
Use;;; const API = ''; // Define actions, 定义操作const getUserOK = ;const getUser = ; // Define reducer, 定义 reducerconst reducer = ; // Generate data, 生成数据const user = ; // Perform the operation, 执行操作user;
set POST/UPDATE/PATCH request 设置为POST/UPDATE/PATCH 请求
; const addUsers = ;const updateUsers = ;const updateUsersX = ; ;;;
Use restful api with pathname
; const API = '';const getUser = ; ;
Use interceptor, 使用拦截器过滤响应
; const myInterceptor = { const json = response; return jsondata;}; ;
Use response result or error
API
API name | API 名称 | description | 描述 |
---|---|---|---|
createFetchAction | create fetch AJAX action | 创建 AJAX 异步操作 | |
{interceptor} | set response interceptor | 设置响应拦截器 |
createFetchAction params config
config name | 配置参数名称 | 描述 | 备注 |
---|---|---|---|
url | 路径 | AJAX 请求的路径 | restful api 的url中参数配置参考 pathname |
{successAction} | 请求成功操作 | ||
{failAction} | 请求成功操作 | ||
{method} | 请求方式 |