Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vue.js/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vue.js 如何将代码从XHR转换为Vue资源?_Vue.js_Xmlhttprequest_Vue Resource - Fatal编程技术网

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);
});