axios

简介: 文章目录引入post请求get请求实例

文章目录


引入

<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>

post请求

// 发起一个post请求
axios({
  method: 'post',
  url: '/user/12345',
  data: {
    firstName: 'Fred',
    lastName: 'Flintstone'
  }
});

get请求

axios({
  method:'get',
  url:'/data.json',
  params:{
    id:12
  }
}).then((res)=>{
     console.log(res)
})

实例

   axios({
            method: "post",
            url: 'http://127.0.0.1:3007/find/findperson',
            data: {
                author: str
            }
        }).then(function (res) {
            const req = res.request
            const response = res.data
            if (req.readyState === 4) {
                if (req.status >= 200 && req.status < 300) {
                    if (response.status == 0) {
                        author.innerText = response['author']
                        id.innerText = response['id']
                        password.innerText = response['password']
                    } else {
                        alert(response["msg"]);
                    }
                }
            }
        }).catch(error => {
            console.log(error);
        })

data 里面的值传到接口内,接口通过req接收

  const user=req.body
    const author=user.author

**function (res)**接收后台传来的参数,

res.data即为上方的一些值


目录
相关文章
|
6月前
|
XML JSON 前端开发
Axios的特点
Axios的特点
32 0
|
4天前
|
XML 存储 JSON
Axios
Axios
7 0
|
6天前
|
JSON 前端开发 JavaScript
axios的详细使用
axios的详细使用
46 1
|
6天前
|
JSON 前端开发 API
axios使用
axios使用
|
6天前
|
存储 设计模式 JSON
快速理解 Axios
快速理解 Axios
46 0
|
6天前
|
前端开发 JavaScript
Axios有哪些常用的方法?
Axios有哪些常用的方法?
35 0
|
7月前
axios详解
axios详解
52 0
|
8月前
|
JSON JavaScript 前端开发
axios的简单的使用
axios的简单的使用
38 0
|
9月前
axios学习
axios学习
|
10月前
|
JSON JavaScript 前端开发
axios是什么
axios是什么
130 1