laravel 5 vue.js csrf 令牌 [英] laravel 5 vue.js csrf token

查看:48
本文介绍了laravel 5 vue.js csrf 令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了让这个 csrf 令牌与 vue.js 示例一起工作,我已经研究了一段时间.

但它一直说我没有令牌.我尝试了各种变体.

底部(不是头部,在身体结束之前)

 <脚本>window.myToken = <?php echo json_encode(['_token' =>csrf_token(),]);?><script src="/js/manifest.js"></script><script src="/js/vendor.js"></script><script src="/js/app.js"></script>

html

@section('内容')<例子></例子>@endsection

控制台输出

未找到CSRF令牌:https://laravel.com/docs/csrf#csrf-x-csrf-tokenvendor.js:7635 您正在开发模式下运行 Vue.确保在部署生产时打开生产模式.在 https://vuejs.org/guide/deployment.html 查看更多提示

示例似乎也没什么用,但我想我需要令牌.

解决方案

如果你研究

<块引用>

/resources/assets/js/bootstrap.js

你会发现

let token = document.head.querySelector('meta[name="csrf-token"]');

你应该在你的<head>标签中添加:

 

此错误将不再显示.

希望能帮到你

I've been at it for a while to get this csrf token to work with the vue.js example.

but it keeps saying i don't have a token. I've tried all kinds of variations.

bottom (not head, before end of body)

    <script>
    window.myToken =  <?php echo json_encode([
        '_token' => csrf_token(),
    ]); ?>
    </script>

    <script src="/js/manifest.js"></script>
    <script src="/js/vendor.js"></script>
    <script src="/js/app.js"></script>

html

<div id="app">
@section('content')
<example></example>
@endsection
</div>

console output

CSRF token not found: https://laravel.com/docs/csrf#csrf-x-csrf-token

vendor.js:7635 You are running Vue in development mode.
Make sure to turn on production mode when deploying for production.
See more tips at https://vuejs.org/guide/deployment.html

Example doesn't seem to do much either, but I guess i need the token.

解决方案

if you look into

/resources/assets/js/bootstrap.js

You will find

let token = document.head.querySelector('meta[name="csrf-token"]');

You should add in your <head> tag this:

 <meta name="csrf-token" content="{{csrf_token()}}">

This error will not be shown anymore.

I hope this helps

这篇关于laravel 5 vue.js csrf 令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆