我正在嘗試學習 laravel,現在我正在將資料傳遞給組件,但每次運行此代碼時都沒有顯示
在我的welcome.blade.php 中:
<x-header name = "Joanna"/>
在我的 Header.php 中:
<?php
namespace App\View\Components;
use Illuminate\View\Component;
class Header extends Component
{
public $name;
/**
* Create a new component instance.
*
* @return void
*/
public function __construct($name)
{
$this->name = $name;
}
/**
* Get the view / contents that represent the component.
*
* @return \Illuminate\Contracts\View\View|\Closure|string
*/
public function render()
{
return view('components.header');
}
}
在我的 header.blade.php 中:
<div>
<h1>Hi {{ $name }}</h1>
</div>
我希望你能幫助我我被困在這幾個小時......謝謝
uj5u.com熱心網友回復:
你的blade component好像不太對。嘗試洗掉 HTML 屬性上的空格,例如:
<x-header name="Joanna" />
uj5u.com熱心網友回復:
您的問題可能就像在您嘗試分配的變數后面添加一個冒號一樣簡單,如檔案中所示:
<x-header :name="Joanna"/>
PHP 運算式和變數應該通過使用 : 字符作為前綴的屬性傳遞給組件:
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/425331.html
