文章目录
引入
<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即为上方的一些值