我正在尝试使用 VueJS 发出 POST 请求。但是,我无法通过 TokenMismatchException。 我在 Blade 主模板中有这个元标记:
<meta name="token" id="token" content="{!! csrf_token() !!}">
这是我的 VueJS 文件的顶部:
Vue.http.headers.common['X-CSRF-TOKEN'] = document.querySelector('#token').getAttribute('value');
这是我的 VueJS 方法中调用 POST 的行:
this.$http.post('ads/create/store', this.content);
我已经尝试了很长时间才让 token 被接受。有人可以帮忙吗?
最佳答案
您应该在元标记和 JS getAttribute
调用中使用 'content' 属性:
html:
<meta id="token" name="token" content="{{ csrf_token() }}">
js:
Vue.http.headers.common['X-CSRF-TOKEN'] = document.querySelector('#token').getAttribute('content');
关于laravel - 使用 Laravel 5.1 和 VueJS 的 TokenMismatchException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34107616/