【发布时间】:2019-01-14 08:32:12
【问题描述】:
我想将XHR中的代码转换为Vue-Resource请求。
XHR:
var data = "channel=default";
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function () {
if (this.readyState === 4) {
console.log(this.responseText);
}
});
xhr.open("POST", "url");
xhr.setRequestHeader("content-type", "application/x-www-form-urlencoded");
xhr.send(data);
这是我在Vue-Resource 中的代码,但出现错误:
this.$http.post(
'url',
{
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: 'channel=default'
}
).then(response => {
console.log(response.body);
}, error => {
console.error(error);
});
我不确定我的vue 代码有什么问题。我需要在 body 参数中传递channel?default。
【问题讨论】:
标签: vue.js xmlhttprequest vue-resource