沃梦达 / IT编程 / 移动开发 / 正文

axios的使用

1.npm安装:npm install axios2.axios发送请求后返回的是一个promise3.axios发送get请求:import axios from axios;axios.get(http://localhost:8080/getData?username=abcid=1).then(res={console.log(res);...

1.npm安装:npm install axios

2.axios发送请求后返回的是一个promise

3.axios发送get请求:

import axios from 'axios';

axios.get('http://localhost:8080/getData?username=abc&id=1').then(res=>{

  console.log(res);

});

参数传递另一种写法:

import axios from 'axios';

axios.get('http://localhost:8080/getData',{params:{id:1,username:'abc'}}).then(res=>{

  console.log(res);

});

4.axios发送post请求:

import axios from 'axios';

axios.post('http://localhost:8080/postData',"name=张三&urs=test").then(res=>{

  console.log(res);

});

本文标题为:axios的使用