(九)Component标签

本节知识点

  • 组件标签
  • 模板标签用的``

概述

<component></component>标签是vue自定义的标签。可以动态绑定我们的组件,根据数据不同更换不同的组件

componet标签

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="initial-scale=1.0,maximum-scale=1.0">
    <title>Title</title>
    <script src="js/vue.js"></script>
</head>
<body>
  <div id="app">
      <component :is="who"></component>
      <button @click="change">点击我变换</button>
  </div>
</body>
<script>
    var jsona = {
        template:`<p>启用第一个模板</p>`
    }
    var jsonb = {
        template:`<p>启用第二个模板</p>`
    }
    var jsonc = {
        template:`<p>启用第三个模板</p>`
    }
    var app = new Vue({
        el:"#app",
        data:{
            who:"jsona"
        },
        components:{
            jsona :jsona,
            jsonb:jsonb,
            jsonc:jsonc
        },
        methods:{
            change:function(){
                if(this.who=="jsona")
                {
                    this.who="jsonb";
                }else if(this.who=="jsonb")
                {
                    this.who = "jsonc";
                }else if(this.who=="jsonc")
                {
                    this.who = "jsona";
                }
            }
        }
    })
</script>
</html>
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容