我这边之前的人封装的
// src/api/index.js
export * from "./xxx.js";
// src/api/xxx.js
export const xxxDetail = (id) => { ... };
export const xxxList = ({ page, ... }) => { ... };
export const xxxSave = ({ id, ... } ) => { ... };
// src/store/modules/xxx.js
import { xxxDetail, xxxList, xxxSave } from "@/utils/api";
import { createState } from "@/utils/state";
const options = createState({ detail: { api: xxxDetail, ... }, list: { api: xxxList, ... }, save: { api: xxxSave, ... });
export default {
namespaced: true,
...options
};
// src/utils/state -- 248 行代码
// createState
/**
* Create a store options
* @
param {Promise} list.api - 获取分页列表数据接口
* @
param {Object} list.params - 发送给接口的参数
* @
param {Function} list.beforeSet - 设置数据之前执行,beforeSet(接口数据)
* @
param {Promise} detail.api - 获取单条数据接口
* @
param {Object} detail.params - 发送给接口的参数
* @
param {Promise} save.api - 保存接口
* @
param {Function} save.success - 保存成功后运行:success({ commit, state, dispatch }, record)
* ....还有很多
*/