laravel5.4 vue Cannot read property 'csrfToken' of undefined

使用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>
    原文作者:小金子
    原文地址: https://segmentfault.com/a/1190000008765060
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞