zoukankan      html  css  js  c++  java
  • component and slot

    component and slot

    使用:

    1.component panel

    <article class="message">
      <div class="message-header">
        <p>Hello World</p>
        <button class="delete" aria-label="delete"></button>
      </div>
      <div class="message-body">
        Lorem ipsum dolor sit amet, consectetur adipiscing elit. <strong>Pellentesque risus mi</strong>, tempus quis placerat ut, porta nec nulla. Vestibulum rhoncus ac ex sit amet fringilla. Nullam gravida purus diam, et dictum <a>felis venenatis</a> efficitur. Aenean ac <em>eleifend lacus</em>, in mollis lectus. Donec sodales, arcu et sollicitudin porttitor, tortor urna tempor ligula, id porttitor mi magna a neque. Donec dui urna, vehicula et sem eget, facilisis sodales sem.
      </div>
    </article>
    

    2.其中header和body需要传入变量

    <article class="message">
      <div class="message-header">
        <p>{{$title}}</p>
        <button class="delete" aria-label="delete"></button>
      </div>
      <div class="message-body">
        {{$content}}
      </div>
    </article>
    

    3.views.components.index 中 需要引用component模版panel

    @component('components.panel')
        @slot('title')
            hello world
        @endslot
        @slot('content')
            have a nice day
        @endslot
    @endcomponent
    

    4.如果要传入默认content

    panel.blade.php修改如下:

     <article class="message">
        <div class="message-header">
          <p>{{$title}}</p>
          <button class="delete" aria-label="delete"></button>
        </div>
        <div class="message-body">
          {{$slot}}
        </div>
      </article>
    

    index.blade.php修改如下

    @component('components.panel')
        @slot('title')
            hello world
        @endslot
            have a nice day
    @endcomponent
    
    //可多来几个:
    
    @component('components.panel')
        @slot('title')
            hello world
        @endslot
        have a nice day123
    @endcomponent
    

    5.还可以这样给默认值:title默认为laravel

    panel.blade.php修改如下:
      
         <article class="message">
            <div class="message-header">
              <p>{{$title ?? 'laravel'}}</p>
              <button class="delete" aria-label="delete"></button>
            </div>
            <div class="message-body">
              {{$slot}}
            </div>
          </article>
    index.blade.php修改如下
        
        @component('components.panel')
                have a nice day
        @endcomponent
  • 相关阅读:
    LotusAdmin帮开发者节省两天开发时间,基于thinkphp6开发的rbac admin(原创)
    Linux自动化分区脚本
    解决github图片无法加载_加快github访问速度
    怎么彻底关闭flash助手弹窗?
    匹配得到A标签href的内容 亲测有效赶紧收藏
    不要再安装vmware-tools了,在 VMware 虚拟机中安装 open-vm-tools可以代替了
    使用root新建管理员用户
    关于我的博客
    C++静态全局变量问题
    SVN 提交子文件夹问题
  • 原文地址:https://www.cnblogs.com/webskill/p/7469576.html
Copyright © 2011-2022 走看看