如何获取Axios数据对象的反应

时间:2020-10-09 06:31:17

标签: javascript reactjs object axios

我正在尝试从localhsot上的api获取数据 我在获取地图数据时遇到问题 下面的控制台屏幕截图enter image description here

这是代码

import React, { Component } from 'react';
import Axios from 'axios';

const api = Axios.create({
    baseURL:`http://localhost/officeapi/api`
});

class SubmitData extends Component {

    state = {
        dataContet: [],
        isLoading: true,
        };

        componentDidMount() {
            api
            .get("/get_form.php")
            .then((res) => {
               // console.log(res)
            this.setState({
             dataContet: res.data,
            isLoading: false
            });
            //console.log(this.state.status);
            })
            .catch((err) => {
            console.log(err);
            });

        };
   

    render () {
       
       // let {status} = this.state.formfiled
      // let { status, dataContet } = this.state;
      //  console.log(this.state.dataContet)
      const { isLoading, dataContet } = this.state;
        return (
              <div className="display from ">
                  {!isLoading ? Object.values(dataContet).map((res, key) => {
                      console.log(res)
                      return(
                      <li key={key}>Oields</li> 
                      )
                  }) : isLoading}
              </div>
             
        );
    }

}

export default SubmitData;

这是api文件https://drive.google.com/file/d/11tH0cx1OvxI29OHOoYYDrANAr9OcZkZQ/view?usp=sharing

0 个答案:

没有答案