Commit 9a0328f0 by zhuxichen

chore: update

parent 6ccef0eb
......@@ -42,6 +42,7 @@ const fetchGlobalConfigAndComponentPath = async () => {
if (props.componentType === 'local') {
const res = await fetchGlobalConfig()
componentPath = res?.componentKV?.[props.componentKey]
// 本地找不到再去远程寻找可用路径 fetchRmoteComponentPath
} else {
componentPath = await fetchRmoteComponentPath()
}
......
<script setup lang="ts">
import { ref, onMounted, getCurrentInstance, defineAsyncComponent } from 'vue'
import { ref, onMounted, getCurrentInstance } from 'vue'
import DynamicComponentLoader from './DynamicComponentLoader.vue'
const instance = getCurrentInstance()
const DynamicComponent = ref(null)
const globalConfig = ref()
const getUrl = () => {
return Promise.resolve(globalConfig.value?.componentKV?.com1)
}
const loadComponent = async () => {
try {
const componentPath = await getUrl() // 获取路径
console.log(componentPath)
// 动态导入组件,确保路径使用 Vite 支持的格式
// 对于vite而言,我需要使用绝对路径,如果需要使用alias
// 则需要先import.meta.glob然后再用map[key]的方式
// 但是对于vue.config.js的项目而言,则是可以使用alias
DynamicComponent.value = defineAsyncComponent(
() => import(/* @vite-ignore */ `${componentPath}`),
)
} catch (error) {
console.error('Error loading component:', error)
}
}
onMounted(() => {
globalConfig.value = instance?.appContext.config.globalProperties
.$globalConfig as Record<string, string | object>
loadComponent()
})
</script>
<template>
<div>{{ $globalConfig?.name }}</div>
<div>{{ globalConfig?.name }}</div>
<!-- <component
:is="DynamicComponent"
v-if="DynamicComponent"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment