Vue3+Vite+TS项目 Component动态引入组件

Vue3+Vite+TS项目 Component动态引入组件

 ***值得注意的点是ref的名称和is绑定的值不要一样,不然会出现警告和不显示组件的情况**
 <template>
  <div>
    <component v-if="queryParams.formType == 'static' && form" ref="formData :is=" form"></component>
  </div>
</template>
<script name="TaskForm" setup>
import { defineAsyncComponent, shallowRef } from 'vue'
const { proxy } = getCurrentInstance();
const viewsModules = import.meta.glob('@/views/**/*.{vue, tsx}');
const dynamicViewsModules = Object.assign({}, { ...viewsModules });
const queryParams = ref({});
const form = shallowRef(null);

const initData = () => {
  queryParams.value = { ...proxy?.$route.query };
  // 自定义组件
  if (queryParams.value.formType == 'static') {
    form.value = defineAsyncComponent(dynamicViewsModules[`/src/views${queryParams.value.formUrl}` + ".vue"])
  }
}
initData();
</script>

如果出现“ TypeError: Cannot read properties of undefined (reading ‘__asyncLoader’)” / “Unhandled error during execution of scheduler” / “The above dynamic import cannot be analyzed by Vite” / “Component is missing template or render function”等情况(错误或者警告)上述代码都可以解决问题!!

  • 5
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 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
发出的红包

打赏作者

yuwenwenwenwenyu

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值