0

我使用 vue-resource 发出这样的帖子请求:

methods: {
        searchNodes: function (val) {
            this.loading = true;
            this.$http.post('/search_query', [val]).then(function (response) {
                this.nodes = response.data;
                this.loading = false;
            }, function (response) {
                console.log(response);
            });
        }
    } 

这是我的路线

Route::post('search_query', 'SearchController@search')->name("search");
    Route::resource('search', 'SearchController'); 

这是我的功能:

public function search(Request $request)
    {
        dd($request->all());
    }

放入网络点击它返回状态代码302并将我重定向到登录页面?

4

3 回答 3

2

只需将 {emulateJSON:true} 添加为您要随请求发送的数据之后的第三个参数。

this.$http.post('link-to-api', data, {emulateJSON:true}).then(function(response){
    // Do something with the response
});
于 2020-10-03T09:29:57.390 回答
0

2 年零 7 个月前我希望你已经找到了这个解决方案

将 vue-resource.js 导入您的代码:

这是链接:https ://cdn.jsdelivr.net/npm/vue-resource@1.5.1

代码VueJs:

methods: {
   searchNodes: function() {
        this.$http.post('YourBackEndpath/', 
          { dataArray:this.colsArray } ).then((resp) => {
            console.log(resp.data);
        });
    }
}

代码 PHP/laravel:

$post = json_decode(file_get_contents('php://input'), true);
    print_r($post['dataArray']);
于 2018-11-15T15:58:10.583 回答
0

我忘记在脚本顶部包含这一行的问题:

Vue.http.headers.common['X-CSRF-TOKEN'] = document.querySelector('#token').getAttribute('content');
于 2016-04-18T07:46:59.290 回答