zoukankan      html  css  js  c++  java
  • takeLatest 如何接受 this.props.dispatch 传递的参数

    1.步骤一

    // 获取查询参数
    getQueryParams(params){
      // 请求月考核分的数据
      this.props.dispatch({
        type:'getMonthlyAssessmentScoreData', // action.type api
        payload: params
      })
    }

    2.步骤二

    // 月考核分
    function* monthlyAssessmentScoreSaga(){
      /**
       * takeLatest
       * 对于触发多个action的时候,只执行最后一个,其他的会自动取消
       */
      yield takeLatest('getMonthlyAssessmentScoreData',(params) => getMonthlyAssessmentScoreList(params))
    }

    3.步骤三

    // 月考核分 请求
    import { getMonthlyAssessmentScorelist } from '../services/api';
    /**
     * 声明时需要添加*,普通函数内部不能使用yield关键字,否则会出错
     * 获取用户列表数据
     */
    function* getMonthlyAssessmentScoreList(params){
      const response = yield call(() => getMonthlyAssessmentScorelist(params)); // 返回值
      // put -- 触发某个action, 作用和dispatch相同
      yield put({ // 考核一览数据
        type:'currentMonthlyAssessmentScoreList', // 触发 同步 monthlyAssessmentScore --> currentMonthlyAssessmentScoreList
        payload:response.data, // 后台获取的数据
      })
    
      yield put({ // 加载动画
        type:'listload',
        payload:false,
      })
    }

    4.步骤四

    // 月考核分
    export async function getMonthlyAssessmentScorelist(param){
      console.log(param);
      return axios.get('http://localhost:8000/monthlyAssessmentScoreList').then(function(response){
        // 接收 json-server 的返回值
        return response.data;
      })
    }

    .

  • 相关阅读:
    如何理解Linux中的load averages?
    如何准备Java初级和高级的技术面试
    大数据java基础吗?
    如何写出没有BUG的代码
    求强连通分量Tarjan算法
    图论_连通_连通分量
    欧拉函数
    二分图,匈牙利算法
    网络流24题(更新中
    一些简单二分题,简单的hash,H(i),字符串题
  • 原文地址:https://www.cnblogs.com/crazycode2/p/9165667.html
Copyright © 2011-2022 走看看