redux 基础

antd 的使用

1.安装npm install antd --save

2.引入到项目中

import 'antd/dist/antd.css'; // or 'antd/dist/antd.less'

3.按需引入

import { Input } from 'antd';

4.添加样式 要使用 {{ }}

例如:

style={{width:"300px"}}

 

 

redux

创建一个store:

先创建reducer

1.先声明一个默认的state

const defaultState = { inputValue:'hello world', list:[1,3]}

2.将state 暴露出去

export default (state=defaultState,action)=>{ return state;}

创建 store并且暴露出去

import { createStore } from 'redux';import reducer from './reducer'let store = createStore(reducer);export default store;

使用store

dataSource={this.state.list}

constructor(props) { super(props); this.state=store.getState(); }

但数据发生改变:

 

1.handleChangeInput(e) {

const action = { type:'change_input_value', value:e.target.value } store.dispatch(action); };

2.action 发送给store, store 不知道要干嘛,就把他发送给reducer ,由reducer 告诉他怎么办

if(action.type === 'change_input_value') { //对state 做一次深拷贝 //redu 不能直接修改state const newState = JSON.parse(JSON.stringify(state)); newState.inputValue=action.value; return newState; }

3.

 

store.subscribe(this.handleChange);

handleChange(e) { this.setState(store.getState()) }

 

redux-devtools的使用:

let store = createStore(reducer,

window.REDUX_DEVTOOLS_EXTENSION && window.REDUX_DEVTOOLS_EXTENSION());

 

 

转载于:https://www.cnblogs.com/guangzhou11/p/9807620.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值