我尝试从livewire组件中传递一个变量:
class Index extends Component
{
public function render()
{
return view('livewire.index')->with('type', config('constants.NONAUTH'));
}
}并从layouts.app访问它:
<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
{{dd($type)}}
@include('includes.head')
...我得到一个错误,$type是没有定义的,正确的方法是什么?
发布于 2020-08-16 12:15:26
声明一个公共变量$type,并在()函数中设置这个变量,如下所示:
class Index extends Component
{
public $type = null;
public function render()
{
return view('livewire.index');
}
public function mount()
{
$this->type = config('constants.NONAUTH');
}
}编辑:
我明白了,我第一次把你搞错了。我又读了一遍,开始理解你想要的东西,因为你想要访问一个在你的应用程序布局之后声明的变量。Livewire在布局加载后立即呈现其组件。我建议您使用livewire来完成您的整个应用程序布局。
是的,可以有各种各样的方式宣布什么东西从直播到你的刀片。这里有一个:
你可以启动一个事件,可以听到全球JS在你的刀片。然后,可以使用jquery / vanilla在刀片组件中设置该值。
https://stackoverflow.com/questions/63422535
复制相似问题