我有集成了 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
,但我不知道如何到达那里,因为标准 phpcsrf_field()
未在 Vue 组件内渲染,我不知道如何导入MyApp.csrfToken
.
<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 模板文件?