Coder Social home page Coder Social logo

learn-dva's Introduction

dva学习

什么是Dva

dva 首先是一个基于 reduxredux-saga 的数据流方案,然后为了简化开发体验,dva 还额外内置了 react-routerfetch,所以也可以理解为一个轻量级的应用框架

dva的简单使用

import dva, { connect } from "dva";
const app = dva();
// 定义模型
app.model({
  namespace: "counter", // 命名空间
  state: { number: 0 }, // 模型对应的状态
  reducers: {
    // 改变仓库状态的reducer
    add(state, action) {
      return { number: state.number + 1 };
    },
  },
});
const Counter = (props) => {
  return (
    <div>
      <h2>{props.number}</h2>
      <button onClick={() => props.dispatch({ type: "counter/add" })}>
        +1
      </button>
    </div>
  );
};
// 连接组件和状态 connect其实就是react-redux里面的 counter是命名空间的名字
const ConnectedCounter = connect(
  (state) => state.counter,
)(Counter);
// 定义路由
app.router(() => <ConnectedCounter />);
// 启动
app.start("#root");

learn-dva's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.