将数据传递到livewire中的组件

时间:2020-08-26 07:52:56

标签: laravel-livewire

这是我的welcome.blade.php

@extends('layouts.app')
@section('content')
<x-frontpage></x-frontpage>
@endsection

这是我的frontpage.blade.php

<h1 class="text-center">{{ $product->name }}</h1>

这是我的错误

$product is not passed to welcome.blade.php

1 个答案:

答案 0 :(得分:0)

您应该在x-frontpage刀片组件中添加道具,否则它将无法接收。

这是一个例子:

<!-- frontpage.blade.php -->

@props(['product'])

<h1 class="text-center">{{ $product->name }}</h1>
<!-- welcome.blade.php -->

@extends('layouts.app')
@section('content')
<x-frontpage :product="$product"></x-frontpage>
@endsection

还要确保您的welcome.blade.php具有$product变量。

更多资源:

https://laravel.com/docs/7.x/blade

https://laravel-livewire.com/docs/rendering-components#render-method