【发布时间】:2017-11-20 00:06:53
【问题描述】:
我只是想用 laravel 学习 vuejs,无法让示例组件正常工作。
我已经创建了一条新的路线来简单地为 vue 示例提供服务。
create.blade.php
<!DOCTYPE html>
<html>
<head>
<title>VUE</title>
</head>
<body>
<h1>example</h1>
<div id="app">
<example></example>
</div>
<script src="/js/app.js"></script>
</body>
</html>
app.js 和 example.vue 文件完全一样开箱即用(所以我不会费心在这里展示 example.vue
require('./bootstrap');
window.Vue = require('vue');
Vue.component('example', require('./components/Example.vue'));
const app = new Vue({
el: '#app'
});
我正在运行npm run watch,它似乎已经构建了应用程序文件。
控制器和路由很好,因为页面正在加载,但我收到如下控制台错误
app.js:1697 Uncaught TypeError: Cannot read property 'csrfToken' of
undefined
at Object.<anonymous> (app.js:1697)
at __webpack_require__ (app.js:20)
at Object.<anonymous> (app.js:778)
at __webpack_require__ (app.js:20)
at Object.<anonymous> (app.js:41430)
at __webpack_require__ (app.js:20)
at app.js:66
at app.js:69
当我单击 chrome 中的控制台错误时,它指向 app.js 中的行:
window.axios.defaults.headers.common['X-CSRF-TOKEN'] =
window.Laravel.csrfToken;
它是否因为我将 csrftoken 用作刀片模板而抱怨? 我怎样才能让它在 laravel 中工作,这样我就可以玩和学习 vuejs 了?
【问题讨论】: