📜  axios 获取请求 javascript stackoverflow - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:01:25.947000             🧑  作者: Mango

代码示例1
constructor(props) {
        super(props);
        this.state = {
            clients: [],
            Code: props.match.params.Code
        };
componentDidMount() {
        axios.get('http://localhost:4000/app/viewclient/' + this.props.match.params.Code).then(function(response) {
            if (response.status >= 400) {
                throw new Error("Bad response from server");
            }
            return response.json();
        }).then(function(data) {
            if (data === "success") {
                this.setState({ msg: "User has been deleted." });
            }
        }).catch(function(err) {
            console.log(err)
        });
    }