我正在尝试创建一个组件,并发送一些数据。
<div class="card">
<div class="card-wrapper">
<div class="card-header">
<div class="card-title">
<i class="fa fa-pie-{{ $icon ?? '' }} fa-fw"></i>
<span>{{ $title ?? '' }}</span>
</div>
<div class="card-version">
<i class="fa fa-question-circle fa-fw"></i>
</div>
</div>
<div class="card-body">
{{ $content ?? '' }}
</div>
</div>
</div>然后,我在Blade中调用该组件
<x-com-card icon="globe" title="Test"> </x-com-card>但是我得到了以下错误
未定义变量$icon
我的组件控制器如下所示
<?php
namespace App\View\Components;
use Illuminate\View\Component;
class ComCard extends Component
{
private $icon;
private $title;
/**
* Create a new component instance.
*
* @param $icon
* @param $title
*/
public function __construct($icon, $title)
{
$this->icon = $icon;
$this->title = $title;
}
/**
* Get the view / contents that represent the component.
*
* @return \Illuminate\Contracts\View\View|string
*/
public function render()
{
return view('com.card');
}
}知道为什么会这样吗?
发布于 2021-03-14 21:05:52
https://stackoverflow.com/questions/66629537
复制相似问题