Javascript 使用vue.js在每个页面上更改laravel变量
我有这样的导航栏:Javascript 使用vue.js在每个页面上更改laravel变量,javascript,php,laravel,vue.js,Javascript,Php,Laravel,Vue.js,我有这样的导航栏: <nav class="navbar"> <p style="text-align: center; color: white;">{{ @$test}}</p> </nav> {{{@$test} 我的页面看起来像: <body class=""> <div id="app"> <div class=""> @include('n
<nav class="navbar">
<p style="text-align: center; color: white;">{{ @$test}}</p>
</nav>
{{{@$test}
我的页面看起来像:
<body class="">
<div id="app">
<div class="">
@include('navbar')
@yield('content') <- here another components
</div>
</div>
</body>
@包括('navbar')
@收益(“内容”)道具是你唯一明智的选择。您必须让它们工作,否则将vue与组件一起使用将是一个毫无意义的练习
根据这一答复:
在组件中使用道具
:
props: ['test'],
<template>
<nav class="navbar">
<p style="text-align: center; color: white;">{{test}}</p>
</nav>
</template>
这里{{$test}
是响应PHP变量test的blade指令
<body class="">
<div id="app">
<div class="">
@php
$test = 'set the right value for test here or anywhere before including the navbar';
@endphp
@include('navbar')
@yield('content') <- here another components
</div>
</div>
</body>
@php
$test='在包含导航栏之前,在此处或任何位置为test设置正确的值';
@endphp
@包括('navbar')
@yield(‘content’)您可能需要定义一个带有道具的导航栏组件use@apokryfos试过:),不起作用你用的是什么版本的Laravel?你想用什么来代替@$test
?那么,我想我的答案是对的,先生?这是我的回答:@HirenGohel是的,这里添加的东西是将PHP变量作为组件属性传递。好的,谢谢您的回复@罗温斯基:请接受我的回答,这样其他用户就不会浪费时间了!结束这个问题
<body class="">
<div id="app">
<div class="">
@php
$test = 'set the right value for test here or anywhere before including the navbar';
@endphp
@include('navbar')
@yield('content') <- here another components
</div>
</div>
</body>