zoukankan      html  css  js  c++  java
  • slot插槽分发

    https://www.cnblogs.com/qq735675958/p/8377761.html

     1 具名slot
     2 
     3 <slot> 元素可以用一个特殊的属性 name 来配置如何分发内容。多个 slot 可以有不同的名字。具名 slot 将匹配内容片段中有对应 slot 特性的元素
     4 
     5 
     6 var childNode = {
     7  template: `
     8  <div class="child">
     9  <p>子组件</p>
    10  <slot name="my-header">头部默认值</slot>
    11  <slot name="my-body">主体默认值</slot>
    12  <slot name="my-footer">尾部默认值</slot>
    13  </div>
    14  `,
    15 };
    16 
    17 var parentNode = {
    18  template: `
    19  <div class="parent">
    20  <p>父组件</p>
    21  <child>
    22   <p slot="my-header">我是头部</p>
    23   <p slot="my-footer">我是尾部</p>
    24  </child>
    25  </div>
    26  `,
    27  components: {
    28  'child': childNode
    29  },
    30 };ps:父组件中利用到的部分就会优先展示父级的信息,否则默认展示子组件的信息;
     1 // 子组件 --slot常用的方式
     2 <template>
     3   <div class="slot-child">
     4    //在子组件中添加slot标签
     5       <slot></slot>
     6       我是slot的子组件
     7   </div>
     8 </template>
     9 
    10 <script>
    11 export default {
    12   name: 'slotChild',
    13   data () {
    14     return {
    15       
    16     }
    17   }
    18 }
    19 </script>
    20 
    21 此时你将这个组件引入到父组件之后,你就可以在
    22 <slot-child>
    23     <div>我就可以在组件内部填充,如果子组件内没写slot,是无法在父页面中展示dom的。<div/>  ps:子组件slot的位置就是插槽的位置。
    24 <slot-child/>    
  • 相关阅读:
    移动端的爬坑路
    判断设备ios或android以及判断是否是微信内置浏览器
    使用vue directive 写好的滑动删除功能
    不用ajax,使用json数据渲染商品的方法
    vue中使用swiper的一些坑
    vue的自定义指令的坑
    better-score获取滑动距离的坑
    linux命令
    关于打印
    数据可视化
  • 原文地址:https://www.cnblogs.com/lujunan/p/11092510.html
Copyright © 2011-2022 走看看