如何设置Vue.http.post数据,使用Vue将数据发送到Laravel路由?

如何设置Vue.http.post数据,使用Vue将数据发送到Laravel路由?,laravel,vue.js,vuejs2,vue-component,Laravel,Vue.js,Vuejs2,Vue Component,我想使用Vue.js向Laravel后端发送post请求。我想不需要任何额外的图书馆。我正在发出一个纯Vue.http.get请求,它就像一个符咒。为了测试Laravel route和Controller返回的数据,我在模板中提出了一个ajax请求,该请求也可以正常工作,返回正确的数据。但是,当我使用Vue时,通过Vue.http.post('My/Controller/Route',data')它不会将post数据发送到控制器 我的Vue.js组件: <template>

我想使用Vue.js向Laravel后端发送post请求。我想不需要任何额外的图书馆。我正在发出一个纯Vue.http.get请求,它就像一个符咒。为了测试Laravel route和Controller返回的数据,我在模板中提出了一个ajax请求,该请求也可以正常工作,返回正确的数据。但是,当我使用Vue时,通过Vue.http.post('My/Controller/Route',data')它不会将post数据发送到控制器

我的Vue.js组件:

<template>
    <div class="opt-pro" v-for="r in profissionais">
        <input :id="r.id" type="checkbox" :value="r.id" v-model="checkedNames" v-on:change="filterResources()"/><label>  {{ r.title }}</label>
    </div>
</template>
<script>
    export default {
        data() {
            return {
                dados: {view: 'dia', pro: [], data: 'Setembro 11, 2017'},
                meus_recursos: [],
                profissionais: [],
                checkedNames: []
            }
        },
        methods:{
            getResources: function() {
                var self = this;
                return Vue.http.get('/admin/getResources').then((response) => {
                _.forEach(response.data.resources,function(item){
                    self.meus_recursos.push(item);
                    self.profissionais.push(item);
                });
                console.log(self.meus_recursos);
            });
        },
        filterResources: function(){
            this.dados.pro = this.checkedNames; // returned by another Vue piece of code - console.log() returns the correct data for this var
            return Vue.http.post('/admin/getAgendamentosPorProfissional', this.dados).then(
                (response) => {
                    console.log(response.body);
                }, 
                (response) => {
                    console.log("Error");
                    console.log(response);
                    console.log(response.body);
                });
        }
    }
它在我的控制台中返回:
{post:Array(0)}

我的jQuery AJAX函数:

public function getAgendamentosPorProfissional(){
       // $view = $_POST['view'];
      // $pro = $_POST['pro'];
      // $data = $_POST['data'];
      $post = $_POST;

      return response()->json(array('post' => $post),200);
}
$.ajax({
      type:'POST',
      url:'/admin/getAgendamentosPorProfissional',
      data:  {"data": data, "view": view, "pro": [pro],"_token": "{{ csrf_token() }}"},
      success:function(data){
        console.log("AJAX - /admin/getAgendamentosPorProfissional");
        console.log(data);
      }
    });
它在我的控制台中返回:

post:
    data: "Setembro 11, 2017",
    pro:["75"]
    view:"dia"
    _token:"6LviacS2KoBqjXxTsFhnTtAQePuEzZ49OMwqBmbM"
这不是CORS问题,因为它从laravel中请求的url返回正确的数据。我怎样才能解决这个问题

我的令牌设置在laravel/resources/assets/js/bootstrap.js文件中:

window.Vue = require('vue');
require('vue-resource');

Vue.http.interceptors.push((request, next) => {
    request.headers.set('X-CSRF-TOKEN', Laravel.csrfToken);
    next();
});

是否缺少方法名?@Bert,是的,组件中还有许多其他方法,它们都可以正常工作。我的问题只是这段代码我的意思是你在
方法中发布的代码不包含在方法中。应该是。我假设它在代码中的某个地方格式正确,否则就永远不会发布。@Bert并且它需要是
方法
而不是
方法
我认为VueResource post和jQuery post之间的主要区别在于
\u标记
是jQuery版本中数据提交的一部分,而不是VueResource版本