【发布时间】:2017-05-15 13:27:42
【问题描述】:
我有集成了 Vue.js 的 Laravel 5.3 项目,我想在我的表单中使用 CSRF-TOKEN。表单html代码在Vue组件文件中
resources / assets / js / bootstrap.js
我有这个:
Vue.http.interceptors.push((request, next) => {
request.headers.set('X-CSRF-TOKEN', MyApp.csrfToken);
next();
});
然后我有主 vue 文件/resources/assets/js/app.js:
require('./bootstrap');
Vue.component('callbackwindow', require('./components/callbackwindow.vue'));
const app = new Vue({
el: '#app',
data: { },
});
然后在 Vue 文件中我需要使用 csrf_field,但我不知道如何获取它,因为标准 php csrf_field() 未在 Vue 组件中呈现,我不知道如何导入 @987654328 @。
<template>
<div class="modal fade" >
<form @submit.prevent="submitForm" name="callback" method="POST" action="/" role="form" class="form-horizontal" enctype="multipart/form-data">
{!! csrf_field() !!}
...form code here...
</form>
</div>
</template>
<script>
export default { }
</script>
是否可以将 MyApp.csrfToken 变量从这里导入到我的 Vue 模板文件中?
【问题讨论】:
标签: php vue.js laravel-5.3 csrf vuejs2