<body>
<!-- 让多个组件使用同一个挂载点,并动态切换,这就是动态组件 -->
<div id="app">
<input type="button" value="第一个组件" @click="aa='hello'">
<input type="button" value="第二个组件" @click="aa='world'">
<component :is="aa"></component>
</div>
</body>
<script>
let vm = new Vue({
el: "#app",
data: {
msg: "水电费水电费",
aa: "hello",
},
components: {
'hello': {
template: '<h1>我是hello组件</h1>'
},
'world': {
template: '<h1>我是world组件</h1>'
},
}
})
</script>
10-21
616
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)