1.1.0 • Published 3 months ago

umi-plugin-dvax v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

Plugin-dvax

umi 插件,dva 用法封装

Install

yarn add umi-plugin-dvax

Usage

启用插件,在.umirc.ts:

export default defineConfig({
  dva: {
    // 跳过model检测
    skipModelValidate: true,
  },
});

在 model 文件内:

import { createModel } from "@@/plugin-dvax";

interface Param {
  a: number;
}

export default createModel<Param>({
  namespace: "test-model",
  state: {
    a: 1,
  },
  // 自定义reducer
  reducer: {
    add: (state, action) => {
      return {
        ...state,
        a: state.a + 1,
      };
    },
  },
});

在组件内使用:

export default function Index() {
  // 响应式获取数据
  const { a } = useSelector(testModel.selector);

  // 非响应式获取数据
  const getState = () => {
    const { a } = testModel.getState();
    return a;
  };

  // 修改
  const update = () => {
    testModel.actions.update({ a: a + 1 });
  };

  // 重置
  const reset = () => {
    testModel.actions.reset();
  };

  // dispatch
  const add = () => {
    testModel.dispatch("add");
  };

  return <div>{a}</div>;
}
1.1.0

3 months ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago