1

Laravel 7 带有组件,并且它具有一个功能,允许我们在视图中检索方法的值作为变量。

它应该像这样工作并在调用组件时打印“这是列表”,但它给了我错误

未定义变量:列表(查看:/home/invito/Documents/Laravel/reparet/resources/views/components/passdata.blade.php)

<?php

namespace App\View\Components;

use Illuminate\View\Component;

class Passdata extends Component
{
    public $title;
    /**
     * Create a new component instance.
     *
     * @return void
     */
    public function __construct($title)
    {
        $this->title = $title;
    }

    /**
     * Get the view / contents that represent the component.
     *
     * @return \Illuminate\View\View|string
     */
    public function render()
    {
        return view('components.passdata');
    }

    public function list()
    {
        return 'This is list';
    }
}

//看法

<div>

   {{$list}}
</div>
4

0 回答 0