zoukankan      html  css  js  c++  java
  • vue slot槽

    <!DOCTYPE html>
    <html>
      <head>
        <meta charset="utf-8">
        <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
      </head>
    
      <body>
        <div id="app">
          <comp> </comp>
    
          <!-- 槽替换 -->
          <comp>
            <p>{{message}}</p>
          </comp>
    
          <comp>
            <i>i标签</i>
          </comp>
    
          <comp>
            <button type="button">按钮</button>
          </comp>
        </div>
    
        <template id="comp">
          <div id="">
            <p>{{message}}</p>
            <slot>
              <!-- 默认槽 -->
              <button type="button">点我</button>
            </slot>
          </div>
        </template>
    
        <script>
          // 子组件
          const comp = Vue.extend({
            template: '#comp',
            data() {
              return {
                message: 'Hello furong!',
              }
            },
          })
    
          // root
          const app = new Vue({
            el: '#app',
            data: {
              message: 'Hello Vue.js!',
            },
            components: {
              comp,
            },
          })
        </script>
      </body>
    </html>
    

  • 相关阅读:
    fibnacci数列递归实现
    求最大公约数伪代码
    第五周学习总结
    第四周学习总结
    我的黑客偶像
    BASE64编码
    第三周学习总结
    第二周学习总结
    Python gui
    SSH实践
  • 原文地址:https://www.cnblogs.com/zhangxuechao/p/14976704.html
Copyright © 2011-2022 走看看