Vue发送请求
1、发送 POST 请求
sendRequest() {
const url = '请求地址';
this.$http.post(url, {}).then(res => {
console.log(res);
});
}
2、发送 GET 请求
sendRequest2() {
const url = '请求地址'
this.$http.get(url).then(res => {
console.log(res)
})
},
3、带请求头的请求
sendRequest() {
const url = "请求地址";
this.$http
.post(
url,
{},
{
headers: {
'Content-Type':'application/x-www-form-urlencoded'
},
}
)
.then((res) => {
console.log(res);
});
},
4、文件下载请求
4.1 使用 POST 请求
export function exportExcel(data) {
const form = document.createElement('form');
form.method = 'post';
form.action = '请求地址?xxx=xxx'
document.body.appendChild(form);
form.submit();
form.remove();
}
4.2 使用 GET 请求
export function exportExcel(data) {
var params = 'xxxxxx';
const url = "请求路径" + params;
const a = document.createElement('a')
a.href = url
document.body.appendChild(a)
a.click()
a.remove()
}