- 与vue的其他组件封装方式一致,区别仅在与如何进行动态组件的渲染## 标准动态组件渲染(组件数量>3,建议使用)
- 动态组件的渲染主要围绕这vue官方提供的 component 组件
- 其原理为:以组件is属性根据不同条件,渲染相应条件的组件
- 1、is属性值取相应组件的名称,如组件的input,即:
- 2、is属性值取相应组件,如组件的import leeInput from "leeInput.vue",即:
- ⚠️ 注意 当使用函数配置动态组件值时,需要:key="type"来实现component组件的动态切换,原因是当type为普通变量时,component组件无法监听type的响应变化
import leeInput from "leeInput.vue"// 获取配置组件const getConfigComponent = (type: string) => { const components: Record<string, any> = { "leeInput1":leeInput, "leeInput2":leeInput, "leeInput3":leeInput, "leeInput4":leeInput, } return components[type]}
## 少量组件渲染(组件数量<=3,建议使用)
git 仓库地址:https://gitee.com/xiaoli-account/vue3_ts.git