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

使用laravel-mix编译后打开页面报错以下:php

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 中添加以下代码便可:webpack

<script>
    window.Laravel = <?php echo json_encode([
        'csrfToken' => csrf_token(),
    ]); ?>
</script>
相关文章
相关标签/搜索