视图 使用 Blade组件传参 显示未定义?

manman10

https://www.workerman.net/doc/webman/view.html#blade%E4%BD%BF%E7%94%A8component%E7%BB%84%E4%BB%B6

Alert.php

<?php

namespace App\user\view\components;

use Illuminate\View\Component;

class Alert extends Component
{

    public $message;

    public function __construct($message=null)
    {

        $this->message = $message;

    }

    public function render()
    {
        return view('components/alert')->rawBody();
    }
}

alert.blade.php

<div class="alert alert-danger">
    {{ $message }}
</div>

调用 组件

<x-alert  :message="$message" />

错误
ErrorException: Undefined variable $message in C:\Users\api\runtime\views\f4f813e9e444674ca156c3f1a9b3ec59b83763d2.php:10

560 1 0
1个回答

manman10

已解决了,谢谢

  • 暂无评论
年代过于久远,无法发表回答
🔝