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>
相關文章
相關標籤/搜索