zoukankan      html  css  js  c++  java
  • Vue——组件的插槽

    组件的插槽:

      代码示例:

      

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>Document</title>
        <script src='../../inputfiles/vue.js'></script>
    </head>
    <body>
            <div id="app">
                    <p>总消费量:{{totalCount}}</p>
                    <tan v-bind:name="name" v-on:tank='add'>
                        // 可以为插槽起名
                        <span slot="haha">哈哈哈!</span>
                        <span slot='heihei'>嘿嘿嘿!</span>
                    </tan>


              // 第二种替换方式
    <tan v-bind:name="name" v-on:tank='add'> // 可以为插槽起名 <template slot='haha'>
                      <span slot="haha">哈哈哈!</span>
                               <h1 slot='heihei'>嘿嘿嘿!</h1>
                  </template>
                    
                      <span slot='heihei'>嘿嘿嘿!</span>

    </tan> </div> <script> // 这里注意一定要用div将template中的标签抱起来 const tanComponent={ template:` <div> <button v-on:click='jump'>{{name}}{{count}}</button> <slot name='haha'></slot> <slot name='heihei'></slot> </div> `, data:function(){ return { count:0 } }, props:{ name:String }, methods:{ jump:function(){ this.count += 1 this.$emit('tank') }, } } var vm = new Vue({ el:"#app", data:{ totalCount:0, name:'奇谈' }, components:{ tan:tanComponent }, methods:{ add:function(){ this.totalCount += 1 } } }) </script> </body> </html>
  • 相关阅读:
    混合模式程序集是针对“v2.0.50727”版的运行时生成的,在没有配置其他信息的情况
    静态static与方法重载
    编写的一个“手机”的类
    面向对象编程(OOP)————修饰符
    POJO
    设计模式——单例模式
    矩形类 求面积
    面向对象编程(OOP)————类
    面向对象编程(OOP)
    for、if循环直至输入正确
  • 原文地址:https://www.cnblogs.com/zsdbk/p/9393835.html
Copyright © 2011-2022 走看看