Vue 动态组件是一种通过 JavaScript 运行时动态切换的组件。它通过使用 v-bind 或 v-bind:is 指令,可以在运行时根据条件动态加载不同的组件。
使用方式:
- 使用 v-bind:is 指令:在模板中,你可以使用 v-bind:is 指令绑定一个动态的组件名称。
<template>
<component v-bind:is="currentComponent"></component>
</template>
<script>
export default {
data() {
return {
currentComponent: 'componentA'
}
}
}
</script>