2017-02-16 34 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,因爲它是預定義的。

相關問題