vue2 component slot

<!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> x</title>
<script src="https://cdn.jsdelivr.net/npm/vue@2.5.22/dist/vue.js"></script>
<style>
.bg_color_odd{
background-color:#0fa367;
}
.bg_color_even{
background-color:#f1f309;
}
.demo-alert-box{
background-color:#ff9931;
}
</style>

</head>
<body>
    <h1>component</h1>
     <h2> slot</h2>
    <hr>
 https://www.cnblogs.com/cisum/p/9618346.html
    <div id="app">        
         <alert-box alert-am="abcd">
           <alert-am alertmessage="cde"></alert-am>
         </alert-box>

        <!-- 具名-->
        <named-slot>
            <span slot='first'>slot first .</span>
            <br>
            <span slot='second'>slot second .</span>        
        </named-slot>

        <!-- scope-->
        <todo-list v-bind:todos="todos">        
          
           <template slot-scope="scope">
                 <p>ALL:{{JSON.stringify(scope)}}</p>                
                 <p>K:{{scope.k}}</p>
                 <p>V:{{scope.v}}</p>
                 
             </template>
         
        </todo-list>         
                           
    </div>
    
 
       
    <script type="text/javascript">
    
    
     Vue.component('named-slot', {
          template: `
            <div class="demo-alert-box">
              <strong>named-slot!</strong>
               <slot name='first'></slot>
               <slot name='second'></slot>
            </div>
          `
        })
    
    Vue.component('todo-list', {
          template: `
            <ul>
              <li v-for="(k,v) in todos" >
                <slot :k="k" :v="v" ></slot>                 
              </li>
            </ul>
          `,
          props:['todos']
        })
    
     
 Vue.component('alert-box', {
          template: `
            <div class="demo-alert-box">
              <strong>Error!</strong>
              <slot></slot>
            </div>
          `
        })
    Vue.component('alert-am', {
          props:['alertmessage'],
          template: `             
              <p><strong>{{alertmessage}}</strong></p>               
          `
        })
       
     

        var app = new Vue({
            el: "#app",
            data:{                              
                xmessage: 'ABC'    ,
                postFontSize:1,
                isToggle:true    ,
                todos:{1:'A',2:'B',3:'C'}        
            }, 
            methods:{
                 
            }            
        })
     
        
     
        
     
    </script>
</body>
</html>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值