使用laravel-mix编译后打开页面报错如下:
Uncaught TypeError: Cannot read property 'csrfToken' of undefined
at Object.<anonymous> (app.3df1225….js:27701)
at __webpack_require__ (app.3df1225….js:20)
at Object.<anonymous> (app.3df1225….js:971)
at __webpack_require__ (app.3df1225….js:20)
at Object.<anonymous> (app.3df1225….js:27722)
at __webpack_require__ (app.3df1225….js:20)
at app.3df1225….js:66
at app.3df1225….js:69
按照github上作者的说法, 在view 中添加如下代码即可:
<script>
window.Laravel = <?php echo json_encode([
'csrfToken' => csrf_token(),
]); ?>
</script>