<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<script type="text/javascript" src="js/vue.js"></script>
<title></title>
</head>
<body>
<h1>Component 标签</h1>
<hr>
<div id="app">
<component v-bind:is="who"></component>
<button @click="changComponent">wwwww</button>
</div>
<script type="text/javascript">
var componentA={
template:`<div style="color:red">I'm componentA</div>`
}
var componentB={
template:`<div style="color:green">I'm componentB</div>`
}
var componentC={
template:`<div style="color:pink">I'm componentC</div>`
}
var app=new Vue({
el:'#app',
data:{
who:'componentA'
},
components:{
"componentA":componentA,
"componentB":componentB,
"componentC":componentC,
},
methods:{
changComponent(){
if(this.who=="componentA"){
this.who="componentB"
}else if(this.who=="componentB"){
this.who="componentC"
}else{
this.who="componentA"
}
}
}
})
</script>
</body>
</html>