-
在
index.blade.php写页面的时候,有的部分是重复使用的,可以封装成组件,多个地方引入使用,这样就避免了大量的重复代码。 -
模板引入格式
// components 表示在 views 下面的 components 文件夹 // header 表示在 views/components/header.blade.php 文件 @include('components.header') -
web.php路由传参Route::get('req', function () { // 传递 return view('index', ['name'=>'dzm']); }); -
新建
header.blade.php组件,并使用传入的页面参数<div>我是头部 {{ $name }}</div> -
index.blade.php页面使用<body> @include('components.header') 页面内容 {{ $name }} </body> -
Demo效果