请求axios方法

1:

 fetch('./01data.json', {})
            //固定格式
            .then(function (response) {
                //resolve 成功
                console.log(response);
                return response.json();
            })
            //获取数据
            .then(function (data) { //将获取到的数据放在data中
                console.log(data);
            })
            //出错
            .catch(function () {
                //reject 失败
            })
2:
  axios.get("./01data.json", {
            // Headers:{ //请求头 进行伪装

            // },
            params: { //params参数
                id: 1001
            }
        })
            .then(function (response) {
                console.log(response.data) //数据
            })
            .catch(function (err) {
                console.log(err)
            })
posted @ 2021-11-23 10:31  熊熊日记  阅读(38)  评论(0)    收藏  举报