zoukankan      html  css  js  c++  java
  • taro 适当封装 Redux,简化调用

    1.适当封装 Redux,简化调用

    src/utils/redux.js

    /**
     * 适当封装 Redux,简化调用
     */
    /* eslint-disable import/prefer-default-export */
    import fetch from './request'
    
    export function createAction(options) {
      const { url, payload, method, fetchOptions, cb, type } = options
      return (dispatch) => {
        return fetch({ url, payload, method, ...fetchOptions }).then((res) => {
          dispatch({ type, payload: cb ? cb(res) : res })
          return res
        })
      }
    }
    

    2.调用

    src/actions/user.js

    import { API_USER_LOGIN } from '@constants/api'
    import { createAction } from '@utils/redux'
    
    /**
     * 用户登录
     * @param {*} payload
     */
    export const dispatchLogin = payload => {
      return createAction({
        url: API_USER_LOGIN, // api请求地址
        type: USER_LOGIN,
        payload
      })
    }
    

    .

  • 相关阅读:
    iOS 内存分配与分区
    iOS 静态库和动态库
    iOS 静态:动态 Pod
    iOS 架构
    基本控件文档-UIScrollView
    UIActivityIndicatorView
    UIControl事件
    UIDatePicker
    UIPageControl
    UIScrollView
  • 原文地址:https://www.cnblogs.com/crazycode2/p/12875966.html
Copyright © 2011-2022 走看看