Redux与获取后台数据相结合

Redux与获取后台数据相结合

一、安装Axios

npm install --save axios

这里的代码进行了组件UI和业务逻辑的拆分,具体方法可参考:https://www.jspang.com/detailed?id=48#toc257:P13进阶:组件UI和业务逻辑的拆分方法,我也是根据此教程进行学习整理的。

二、TodoList.js

1、引入axios

import axios from 'axios'

2、在组件的声明周期函数里componentDidMount获取远程接口数据

componentDidMount() {
   
  //这里的接口是我们自己项目中的地址,你可以自己找其他接口或者自己写一个mock假数据
  axios.get('http://sy.aerozhonghuan.com:81/test/qdfaw/api/qingqi/sellbusiness/queryDataDictList?code=VOD1').then((res) => {
   
        const data = res.data.data;
        const action = getListAction(data)
        store.dispatch(action)
  })
}

3、完整代码示例:

import React, {
    Component } from "react";  
import 'antd/dist/antd.css'
import store from './store/index' 
import {
    changeInputAction, addItemAction, delItemAction, getListAction } from './store/actionCreators'
import TodoListUI from './TodoListUI'  //ui拆分
import axios from 'axios'

class TodoList extends Component {
      
    constructor(props) {
   
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值