unplugin / unplugin-vue-components

📲 On-demand components auto importing for Vue
https://www.npmjs.com/package/unplugin-vue-components
MIT License
3.76k stars 349 forks source link

vue component 组件动态注册 #465

Closed qq1066536 closed 2 years ago

qq1066536 commented 2 years ago

Clear and concise description of the problem

<template>
    <el-form
        :ref="formRef"
        :model="form"
        :rules="rules"
        size="small"
        :validate-on-rule-change="false">
        <el-row>
            <el-col v-for="column in columns" v-bind="response" :key="column.prop">
                <el-form-item :label="column.label" :prop="column.prop">
                    <component :is="column.component" />
                </el-form-item>
            </el-col>
        </el-row>
    </el-form>
</template>
<script setup lang='ts'>
import { reactive} from "vue"
const columns = reactive([
    {
        prop: 'userName',
        label: '用户名',
        component: 'el-input',
    },
]);
</script>

使用vue自带component组件,生成动态组件时,按需加载无法正常加载,需要手动导入组件和样式

Suggested solution

新增includes 属性或者类型于unplugin-auto-import 中的imports 属性,自动导入指定的组件

Alternative

No response

Additional context

No response

Validations

vfiee commented 2 years ago

Same problem. Hope to fix it soon

sxzz commented 2 years ago

Please use https://github.com/antfu/unplugin-auto-import, and do not use string literal 'el-input', use ElInput variable instead.