fix: 预览页改成hook写法

This commit is contained in:
MTrun
2022-03-17 10:53:18 +08:00
parent b101b2b857
commit c399277350
5 changed files with 77 additions and 52 deletions
@@ -0,0 +1,28 @@
import { ref } from 'vue'
import { ChartEditStorageType } from '../index.d'
import { CreateComponentType } from '@/packages/index.d'
import { fetchChartComponent } from '@/packages/index'
export const useComInstall = (localStorageInfo: ChartEditStorageType) => {
const show = ref(false)
// 注册组件(一开始无法获取window['$vue'])
const intervalTiming = setInterval(() => {
if (window['$vue'].component) {
clearInterval(intervalTiming)
show.value = true
localStorageInfo.componentList.forEach(async (e: CreateComponentType) => {
if (!window['$vue'].component(e.chartConfig.chartKey)) {
window['$vue'].component(
e.chartConfig.chartKey,
fetchChartComponent(e.chartConfig)
)
}
})
}
}, 200)
return {
show
}
}