【问题标题】:Pass data to component in livewire将数据传递给 livewire 中的组件
【发布时间】:2020-12-14 23:31:33
【问题描述】:

这是我的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

【问题讨论】:

    标签: laravel-livewire


    【解决方案1】:

    你应该给你的x-frontpage刀片组件添加一个props,否则它将无法接收它。

    这是一个例子:

    <!-- 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

    【讨论】:

      猜你喜欢
      • 2022-01-16
      • 2021-09-02
      • 1970-01-01
      • 2020-08-05
      • 2020-10-23
      • 2019-01-31
      • 2018-09-12
      • 2016-04-04
      • 2023-03-04
      相关资源
      最近更新 更多