繁体   English   中英

在laravel + vue.js中广播数据

[英]Broadcast data in laravel + vue.js

我需要使用社交按钮创建菜单

我有主模板

<!doctype html>
<html lang="{{ app()->getLocale() }}">
<head>
    <title>Lapins - @yield('title')</title>
    @include('head')
</head>
<body>

    <div id="lapins">
        @include('components/header')

        @yield('content')
    </div>

    <script src="js/app.js"></script>
</body>
</html>

这是我的模板路由器

Route::get('/', function () {
    $headerBar = [
        'socials' => [
            [
                'name' => 'Email',
                'type' => 'email',
                'value' => 'support@lapins.com.ua'
            ],
            [
                'name' => 'Phone',
                'type' => 'bell',
                'value' => '066 866 14 23'
            ],
            [
                'name' => 'Facebook',
                'type' => 'facebook',
                'value' => 'http://facebook.com/'
            ],
            [
                'name' => 'Twitter',
                'type' => 'twitter',
                'value' => 'http://twitter.com/'
            ],
            [
                'name' => 'Pinterest',
                'type' => 'pinterest',
                'value' => 'http://pinterest.com/'
            ]
        ]
    ];

    return view('layouts.index', $headerBar);
});

我如何在@include('components / header')中广播$ headerBar? 还是这不是解决此任务的正确方法?

您只需执行以下操作即可将变量传递给Include:

@include('page',['components.header' => $headerBar])

注意:您可以使用点符号来访问部分

'folder.subfolder.file' and not 'folder/subfolder/file'

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM