vue 在使用组件时,大部分都在使用同步组件和动态组件,少数部分使用 异步组件。
1. 动态组件 普通做法
背景:一个组件显示,另外一个组件隐藏,反之。
<script>
// 创建 vue实例
const app = Vue.createApp({
data() {
return {
currentItem: 'input-item'
}
},
methods:{
handleClick() {
if (this.currentItem === 'input-item') {
this.currentItem = 'common-item'
} else {
this.currentItem = 'input-item'
}
}
},
// 动态组件
template: `
<input-item v-show=" currentItem === 'input-item' "/>
<common-item v-show=" currentItem === 'common-item' "/>
<button @click=</