js axios配置和响应

  配置

    <script src="../node_modules/axios/dist/axios.js"></script>
    <script>
        //配置
        const instance = axios.create({
            //设置根路径
            baseURL: 'http://localhost:5000/Test/',
            //设置超时
            timeout: 1000,
        });

        instance.get('g1')
            .then(function (response) {
                console.log(response.data)
            }).catch(function (err) {
                console.log(err)
            });

    </script>

 

 

响应

axios.get('/user/12345')
  .then(function (response) {
    //服务端的响应数据
    console.log(response.data);
    //服务端的响应状态码
    console.log(response.status);
    //?
    console.log(response.statusText);
    //服务端响应头
    console.log(response.headers);
    //axios请求配置
    console.log(response.config);
  });

 

posted @ 2021-06-14 15:45  富坚老贼  阅读(199)  评论(0编辑  收藏  举报