(九)Component标签

2018-02-15  本文已影响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>
上一篇 下一篇

猜你喜欢

热点阅读