npm install axios
import axios from 'axios'
axios.get("http://localhost:5000/students").then(
(response) => {
console.log("请求成功了", response.data);
},
(error) => {
console.log("请求失败了", error.message);
}
);
地址拼接字符this.searchInfo
axios
.get(`https://api.github.com/search/users?q=${this.searchInfo}`)
.then(
(response) => {
console.log("请求成功了", response.data);
},
(error) => {
console.log("请求失败了", error.message);
}
);
代理一
devServer: {
proxy: 'http://localhost:4000'
}
代理二
devServer: {
proxy: {
'/api': {
target: '<url>',
pathRewrite:{'^/api':''},
ws: true,
changeOrigin: true
},
'/foo': {
target: '<other_url>'
}
}
}