美文网首页
VUE组件插槽

VUE组件插槽

作者: 小黄不头秃 | 来源:发表于2023-06-06 03:15 被阅读0次
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <!-- 
        组件插槽的作用
            - 父组件向子组件传递内容
     -->

     <!-- 
         组件插槽的基本用法:
         (1)插槽位置
         Vue.component('alert-box',{
             template:`
             <div class="demo-alert-box">
                 <strong>error!</strong>
                 <slot></slot>
             </div>
             `
         }
         );
         (2)插槽内容
         <alert-box>Something bad happened.</alert-box>
      -->
      
      <div id="app">
          <alert-box>有BUG发生!</alert-box>
          <alert-box>有一个warnning!</alert-box>
          <alert-box></alert-box>
      </div>
      <script src="./vue/vue.js"></script>
      <script>
          Vue.component('alert-box',{
              template:`
             <div>
                <strong>ERROR:</strong>
                <slot>默认</slot>
             </div>`
          });
          var vm = new Vue({
              el:"#app",
              data:{},
              methods:{}
          });
      </script>
</body>
</html>

相关文章

  • vue插槽slot

    -具名插槽 子组件Demo.vue 引用子组件的页面 -作用域插槽 子组件Demo.vue 引用子组件的页面

  • 【Vue】组件 - 插槽默认值

    基础知识 【Vue】组件 - 插槽的基本用法 【Vue】组件 - 多个插槽 子组件里,在 里写上默认的内容。 在父...

  • 2020-07-23 一次性讲明白vue插槽slot

    vue插槽slot 一、前言 vue官方文档中在"组件基础"内容中提到组件可以通过插槽分发内容,那插槽是怎么使用的...

  • vue插槽slot

    vue插槽slot 一、前言 vue官方文档中在"组件基础"内容中提到组件可以通过插槽分发内容,那插槽是怎么使用的...

  • Vue总结4-插槽,Vuex,VueRouter

    1.插槽 1.1匿名插槽 52-Vue组件-匿名插槽 ...

  • Vue插槽

    Vue 插槽 插槽用于向组件传递内容,插槽内可以包含任何模板代码,包括 HTML,甚至组件。如果 组件 没有包含一...

  • 插槽v-slot

    父子组件插槽的使用 父组件product.vue 子组件 ProductParam.vue

  • vue具名插槽使用

    插槽用法:子组件header固定;父组件outside插槽header/index.vue outside/ind...

  • vue 插槽

    插槽语法是Vue实现的内容分发API,用于复合组件开发。 匿名插槽 具名插槽 作用域插槽 将内容分发到子组件指定位置

  • Vue3:Slot 插槽

    1、匿名插槽 1.1 什么是插槽 插槽(Slot)是 vue 为组件的封装者提供的能力。允许开发者在封装组件时,把...

网友评论

      本文标题:VUE组件插槽

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