zoukankan      html  css  js  c++  java
  • vue component动态组件

    下面看下vue component动态组件

     动态组件

    通过component标签 的is属性来进行组件的切换

    is的属性值决定要显示的组件,所以将is的属性值设置为data中的值,以便于动态变化

    1
    2
    3
    4
    5
    6
    7
    <template>
      <div class="app">
          <component :is="组件名称">
      
          </component>
      </div>
    </template>
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    <!DOCTYPE html>
    <html lang="en">
    <head>
      <meta charset="UTF-8">
      <title>动态组件</title>
      <script src="bower_components/vue/dist/vue.js"></script>
      <style>
      </style>
    </head>
    <body>
      <div id="box">
        <input type="button" @click="a='aaa'" value="aaa组件">
        <input type="button" @click="a='bbb'" value="bbb组件">
        <component :is="a"></component> <!-- 动态组件-->
      </div>
     
      <script>
        var vm=new Vue({
          el:'#box',
          data:{
            a:'aaa'
          },
          components:{
            'aaa':{
              template:'<h2>我是aaa组件</h2>'
            },
            'bbb':{
              template:'<h2>我是bbb组件</h2>'
            }
          }
        });
     
      </script>
    </body>
    </html>
     
  • 相关阅读:
    Pipe
    An Easy Problem?!
    Kadj Squares
    Space Ant
    Intersection
    让网页变为可编辑状态
    typescript入门基础
    大家都能看懂的 canvas基础教程
    数组的foreach方法和jQuery中的each方法
    html单行、多行文本溢出隐藏
  • 原文地址:https://www.cnblogs.com/h2zZhou/p/12437363.html
Copyright © 2011-2022 走看看