zoukankan      html  css  js  c++  java
  • React里面的redux的简单使用

    第一步 

      actions文件:

          

    // export function getName (options) {

    //   return {
    //       type: "DATA",
    //       payload: options
    //   }
    // }
     
    第二步 
       reducer文件:
         

           

    // const defaultState = {
    //   name: ''
    // }

    // export default function (state = defaultState, action) {
    //   switch (action.type) {
    //     case 'DATA':
    //       return {
    //         ...state,
    //         name: action.payload
    //       }  
    //     default:
    //       return state
    //   }
    // }
     
    第三步: 
           页面中引入
          connect   from react-redux
     
        
    export default @connect(state => ({}),{
      getName
    })
      
    第四部  
       请求参数的时候我们可以通过this.props.getName() 把name存进去
      
     
     
     
  • 相关阅读:
    297. Serialize and Deserialize Binary Tree
    331. Verify Preorder Serialization of a Binary Tree
    332. Reconstruct Itinerary
    329. Longest Increasing Path in a Matrix
    319. Bulb Switcher
    292. Nim Game
    299. Bulls and Cows
    Ice Cream Tower Gym
    B
    C
  • 原文地址:https://www.cnblogs.com/LC123456/p/12880082.html
Copyright © 2011-2022 走看看