Vue.js 如何将代码从XHR转换为Vue资源?
我想将Vue.js 如何将代码从XHR转换为Vue资源?,vue.js,xmlhttprequest,vue-resource,Vue.js,Xmlhttprequest,Vue Resource,我想将XHR中的代码转换为Vue资源请求 XHR: 这是我在Vue资源中的代码,但我得到一个错误: this.$http.post( 'url', { headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, body: 'channel=default' } ).then(response => {
XHR
中的代码转换为Vue资源
请求
XHR:
这是我在Vue资源中的代码,但我得到一个错误:
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
。您可以将数据作为第二个参数传递给.post
方法
它必须是JSON格式。
this.$http.post(
'url',
{ channel: 'default'},
{
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
}
).then(response => {
console.log(response.body);
}, error => {
console.error(error);
});
这还不可能,我可以在大约5分钟内完成。当然,没问题!:)如果我想传递一些参数?在标题下传递对象是否正确<代码>{data:{property:'test',id:1}}
?什么类型的参数?一个是数字,另一个是字符串,只是一些数据
this.$http.post(
'url',
{ channel: 'default'},
{
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
}
).then(response => {
console.log(response.body);
}, error => {
console.error(error);
});