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

    下面看下vue component动态组件(详情看vue.js官网动态组件)

     动态组件

    通过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>
  • 相关阅读:
    SSL和SSH的差别
    cocos2d-x 3.0游戏实例学习笔记 《跑酷》 第五步--button控制主角Jump&amp;Crouch
    UVA
    程序员,你们这么拼是找不到妹纸的!
    组件:表行组件
    表单修饰符.lazy.number.trim
    表单下拉框select
    表单单选按钮input[type="radio"]
    表单复选框input[type="checkbox"]
    表单控件绑定v-model
  • 原文地址:https://www.cnblogs.com/fsg6/p/14383449.html
Copyright © 2011-2022 走看看