vue3+vite 批量引入组件动态使用

引入组件

const modules = import.meta.glob('./components-new/*.vue');
const components: any = ref({});
Object.entries(modules).forEach(([path, asyncCom]) => {
  const name = path.replace(/\.\/components-new\/(.*)\.vue/, '$1');
  components.value[name] = markRaw(defineAsyncComponent(asyncCom));
});

动态使用组件

<div v-for="(item, index) in componentList" :key="index" class="wow">
      <template v-if="item.show">
        <component :is="components[item.name]"></component>
      </template>
    </div>

控制组件显隐与顺序


const componentList: any = ref([
  { name: 'comp1', show: false },
  { name: 'comp2', show: false },
  { name: 'comp3', show: false },
  { name: 'comp4', show: false },
  { name: 'comp5', show: false },
  { name: 'comp6', show: false },
  { name: 'comp7', show: false },
]);
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Vue 3 + Vite + TypeScript中使用EditableProTable组件可以按照以下步骤进行: 1. 首先,确保你已经安装了Ant Design Vue和EditableProTable组件。你可以使用以下命令进行安装: ```bash npm install ant-design-vue@next npm install @ant-design/pro-table@next ``` 2. 在你的Vue组件引入EditableProTable组件和相应的样式: ```vue <template> <a-table-pro :columns="columns" :request="fetchData" :rowKey="record => record.id" :pagination="pagination" :loading="loading" :options="options" :actionRef="actionRef"></a-table-pro> </template> <script> import { defineComponent, ref } from 'vue' import { EditableProTable } from '@ant-design/pro-table' export default defineComponent({ components: { ATablePro: EditableProTable, }, setup() { const columns = [ // 列配置 ] const fetchData = async (params) => { // 发起请求获取数据 } const loading = ref(false) const pagination = ref({ current: 1, pageSize: 10, }) const options = ref({}) const actionRef = ref(null) return { columns, fetchData, loading, pagination, options, actionRef, } }, }) </script> <style lang="less"> @import '~@ant-design/pro-table/dist/component.less'; </style> ``` 3. 根据你的需要,配置EditableProTable的列配置和数据请求逻辑。你可以根据Ant Design Vue的Table组件和EditableProTable的文档进行配置。 这样,在Vue 3 + Vite + TypeScript中,你就可以使用EditableProTable组件了。根据你的实际情况,你可能需要进行一些额外的配置和样式调整。请参考Ant Design Vue和EditableProTable的文档进行进一步的学习和调整。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值