美文网首页
(九)Component标签

(九)Component标签

作者: 我拥抱着我的未来 | 来源:发表于2018-02-15 12:23 被阅读0次

本节知识点

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

概述

<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>

相关文章

网友评论

      本文标题:(九)Component标签

      本文链接:https://www.haomeiwen.com/subject/dwzytftx.html