首页 > 其他 > 详细

redux笔记1

时间:2019-03-16 18:44:25      阅读:183      评论:0      收藏:0      [点我收藏+]

1.安装redux  使用  npm install -save redux  安装redux,注意使用-save 表示安装到依赖中;

2. 创建store文件夹,下面创建 index.js 和 reducer.js文件;

index.js:

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

reducer.js 

const defaultState ={
    inputValue:‘默认信息‘,
    list:[]
};
export default (state = defaultState ,action)=>{
  return state;
}

在html中调用:


import store from ‘./store‘
constructor(props){
    super(props);
    this.state = store.getState();//redux 提供的获取数据的方法
    console.log(this.state);
}

 

redux笔记1

原文:https://www.cnblogs.com/xiaozhumaopao/p/10543611.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!