老莫的笔记本  
  
查看: 779|回复: 0

React redux actionType 的拆分 与 actionCreator的使用

[复制链接]

662

主题

878

帖子

5141

积分

超级版主

Rank: 8Rank: 8

积分
5141
发表于 2020-9-6 14:12:03 | 显示全部楼层 |阅读模式
1. actionType 的拆分  纯粹是无聊, 本质意义是搞个 js 文件,把所有的 type 都放进去 ,这步甚至不如swicth 来的方便 -。- 暂且不管他;
2. actionCreator 这玩意呢 ,也是搞个js ,然后 利用传值调用,其实吧 就是把所有action 都集中起来;

  2.1 actionCreator.js
  1. // 这个主要用来统一管理 action

  2. export  const actionChangInpValue = (value)=>({
  3.     type: "chang_inp_value",
  4.     value:value
  5.    
  6. });

  7. export const actionChangList = (index)=>({
  8.     type:'chang_list',
  9.     index
  10. })
复制代码



2.2 TODOlist.js
  1. import {actionChangInpValue ,actionChangList } from '../store/ActionCreates';








  2. // 监听input改变
  3.     inpC(e){
  4.         // this.setState({
  5.         //     inpValue:e.target.value
  6.         // })
  7.         // console.log(e.target.value)
  8.         
  9.         // 修改之后的数据
  10.         // let action = {
  11.         //     type :'chang_inp_value',
  12.         //     value:e.target.value
  13.         // }

  14.         // 传给数据处理中心中心 利用 dispatch 方法
  15.         store.dispatch( actionChangInpValue(e.target.value)  );
  16.         
  17.     }
复制代码


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表