小编inf*_*ing的帖子

React axios response.json 不是一个函数

我不断收到一条错误,指出 response.json 不是我的 axios 请求数据的函数。我不知道为什么这个代码在两天前起作用...我尝试乱搞承诺,看看这是否会有所作为,但似乎不会。代码在下面,非常感谢任何帮助

import React, { Component } from 'react'
import TrackingRender from '../TrackingRender/TrackingRender'
import axios from 'axios'
import { Redirect } from 'react-router';


export class OrderTracking extends Component {
    constructor() {
        super()
        this.state = {
            loadingData: true,
            order: []
        }
    }
    async componentDidMount() {
        this._isMounted = true;
        if (this.state.loadingData) {
            try {
                const { id } = this.props.match.params
                const response = await axios.get(`http://localhost:5000/api/orders/${id}`)
                const data = await response.json()
                this.setState({
                    order: data,
                    loadingData: false
                })
                console.log(this.state)
            } catch …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs axios

1
推荐指数
1
解决办法
8098
查看次数

标签 统计

axios ×1

javascript ×1

reactjs ×1