美文网首页Vue
在vue中使用插槽

在vue中使用插槽

作者: 程序员同行者 | 来源:发表于2018-07-12 18:35 被阅读0次

slot 插槽

<!DOCTYPE html>
<html>
<head>
   <title>在vue中使用插槽</title>
   <script src="./vue.js"></script>
</head>
<body>
   <!-- // 父组件给子组件插入额外的dom区块 -->
   <!-- // 这里定义了2个具名插槽 一个叫header一个叫footer -->
   <div id='app'>
       <counter>
           <div class="header" slot="header">header</div>
           <div class="footer" slot="footer">footer</div>
       </counter>
       
   </div>


   <!-- // 作用域插槽 -->
   <!-- // 作用域插槽必须是一个template开头和结尾的,同时要声明从子组件传来的数据放在哪,slot-scope='props'这个指定。还有接收过来的数据改如何展示 -->
   <div id='app-1'>
       <child>
           <template slot-scope='props'>
               <li>{{props.item}} -- hello</li>
               
           </template>
       </child>
   </div>
<script>

   var counter = {
       template: `<div >
                   <slot name="header"></slot>
                   <div class="content">content</div>
                   <slot name="footer"></slot>
                   </div>`,
   
   }

   var vm =  new Vue({
       el:'#app',
       components: {
           counter: counter
       },
       
   })


   var child = {
       data: function() {
           return {
               list: [1,2,3,4,5]
           }
       },
       template: `<div>
                   <ul>
                   <slot v-for="item of list"
                       :item="item">
                   </slot>
                   </ul>
                   </div>`
   
   }

   var vm1 =  new Vue({
       el:'#app-1',
       components: {
           child: child
       }
   })
</script>
</body>
</html>

相关文章

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

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

  • vue插槽slot

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

  • 18、Vue3 作用域插槽

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

  • (十八)补充-Vue3中插槽的使用

    本章我们将了解到的是vue3中常用插槽的使用; vue3中的插槽是在用的时候和vue2的区别略有不同,常见插槽使用...

  • 详解vue中的插槽

    1.在vue中插槽分为具名插槽和非具名插槽;而插槽的使用主要是我们在页面中存在很多个相似但却重复的部分; 首先我以...

  • vue插槽

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

  • vue 插槽的使用

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

  • 在vue中插槽的使用

  • 在Vue中如何使用插槽

    很重要,很多第三方的Vue的插件或者模块中都大量的使用了插槽这种特性。使用场景:Vue父组件向子组件传递dom结构...

  • 2019.2.12 (vue中slot卡槽)

    插槽 在vue中,我们会在开发中经常会使用到插槽slot,通过网上文章的学习,主要参考了这篇文章;https://...

网友评论

    本文标题:在vue中使用插槽

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