美文网首页
Vue中slot的使用

Vue中slot的使用

作者: Sunshine_Boys | 来源:发表于2021-06-01 16:18 被阅读0次

在Vue中我们都是用过slot,但是如果更高的定义与使用是个难题,本文就带你解锁这个技能。

直接上代码

  1. 组件部分
<template>
  <div class="view">
      <div class="header">
          <slot></slot>
      </div>
      <div class="content">
          <slot name="content"></slot>
      </div>
      <div class="foot">
          <slot name="foot" v-bind="{isShow:true}"></slot>
      </div>
  </div>
</template>
  1. 使用
<template>
  <div class="view">
    <component0>
      <template>
        <div>头部(默认插槽)</div>
      </template>
      <template v-slot:content>
        <div>内容(具名插槽)</div>
      </template>
      <template v-slot:foot="param">
          <div>尾部内容</div>
        <div v-if="param.isShow">是否展示尾部 备案说明(作用域插槽)</div>
      </template>
    </component0>
  </div>
</template>
<script>
import component0 from "./component0";
export default {
  components: {
    component0,
  },
};
</script>

个人理解

  • slot 用的好就是事半功倍,用的不好就是坑后人
  • slot 中配合使用其他组件达到组件的组合使用
  • 作用于slot 多用于动态组件中

相关文章

  • vue template 中 slot-scope/scope

    vue template 中 slot-scope/scope 的使用在vue 2.5.0+ 中slot-scop...

  • vue插槽

    vue插槽slot的理解与使用 vue slot插槽的使用介绍及总结

  • 18、Vue3 作用域插槽

    作用域插槽:让插槽内容能够访问子组件中,vue2中作用域插槽使用slot-scope,vue3中使用v-slot ...

  • Vue3.0 组件的核心概念_插槽

    Vue 在 2.6 版本中,对插槽使用 v-slot 新语法,取代了旧语法的 slot 和 slot-scope,...

  • Web Component中使用slot

    Web Component中使用slot的使用方式与vue中slot很像,或许后者借用了前者的思想。 Web Co...

  • vue 插槽的使用

    vue 插槽手册 深入理解vue中的slot与slot-scope 插槽的使用其实是很简单首先要明白插槽是使用在子...

  • 27.Vue slot内容分发-解构

    Vue slot的使用参考:26.Vue slot内容分发 什么是slot分发解构:官方定义:如果一个 JavaS...

  • vue

    vue关于slot、render的用法 通过下面一段代码展示 slota. 具名slot使用:在组件中通过 定义...

  • Vue中slot的使用

    在Vue中我们都是用过slot,但是如果更高的定义与使用是个难题,本文就带你解锁这个技能。 直接上代码 组件部分 ...

  • vue slot

    vue slot用法1: slot主要是让组件的可扩展性更强 1.匿名slot使用 //定义组件 //使用方法 <...

网友评论

      本文标题:Vue中slot的使用

      本文链接:https://www.haomeiwen.com/subject/bvawsltx.html