2017-02-16 85 views
-2

我使用laravel 5.4作为后端,并使用Vue.js作为前端。我将使用Vue将值传递给Controller并存储数据。但是,当我检查控制台,响应显示错误

自动填充$HTTP_RAW_POST_DATA已取消,将 在未来的版本中删除。

我使用的服务器是WAMPServer 3.0.6。 我发现解决方案正在改变php.ini,$HTTP_RAW_POST_DATA=-1,但仍然有错误。

那么还有其他解决方案吗?

这是我的Vue公司代码

<script> 
export default { 
    mounted(){ 

    }, 

    data() { 
     return { 
      content :'', 
      not_working: true 
     } 
    }, 

    methods:{ 
     create_post() { 
      this.$http.post('/create/post', { content:this.content }) 
       .then((resp)=> { 
        this.content = '' 
        noty({ 
         type: 'success', 
         layout: 'bottomRight', 
         text: 'Your post has been posted.' 
        }); 
        console.log(resp) 

      }) 
     } 
    }, 

    watch :{ 
     content(){ 
      if(this.content.length > 0) 
       this.not_working = false 
      else 
       this.not_working= true 
     } 
    } 
} 

我的控制器

public function store(Request $request){ 

    return Post::create([ 
     'body' => $request->content, 
     'user_id' => Auth::id() 

    ]); 

} 

更新: 后,我从互联网研究,似乎是解决了问题,但发生了新的问题,这是

TokenMismatchException 

我包括了<meta name="csrf-token" content="{{ csrf_token() }}">

但仍然有这个错误,我现在该怎么办?

+0

首先 - 你使用的是Axios还是vue-resource? –

+0

我仍然使用vue-resource ... – masterhunter

+0

用axios来代替它 –

回答

1

因为我懒得找到添加令牌到vue资源函数的方法。然后我把它改成axios,因为它可以避免这个错误。所以,我只是改变

this.$http.post('/create/post', { content:this.content }) 

axios.post('/create/post', { content:this.content }) 

那么它可以解决CSRF令牌的问题。我认为这只适用于laravel 5.4,因为它是预定义的。

相关问题