mirror of
https://github.com/vbenjs/vue-vben-admin.git
synced 2025-01-23 09:40:25 +08:00
feat(Preview): 优化实例创建更新逻辑, 防止重复创建dom (#3979)
* perf(Preview): 优化实例创建更新逻辑, 防止重复创建dom * perf: 逻辑优化
This commit is contained in:
parent
5b7b6b1780
commit
25699c0b60
@ -1,7 +1,7 @@
|
||||
import type { Options, Props } from './typing';
|
||||
import ImgPreview from './Functional.vue';
|
||||
import { isClient } from '@/utils/is';
|
||||
import { createVNode, render } from 'vue';
|
||||
import ImgPreview from './Functional.vue';
|
||||
import type { Options, Props } from './typing';
|
||||
|
||||
let instance: ReturnType<typeof createVNode> | null = null;
|
||||
export function createImgPreview(options: Options) {
|
||||
@ -10,8 +10,13 @@ export function createImgPreview(options: Options) {
|
||||
const container = document.createElement('div');
|
||||
Object.assign(propsData, { show: true, index: 0, scaleStep: 100 }, options);
|
||||
|
||||
instance = createVNode(ImgPreview, propsData);
|
||||
render(instance, container);
|
||||
document.body.appendChild(container);
|
||||
if (instance?.component) {
|
||||
// 存在实例时,更新props
|
||||
Object.assign(instance.component.props, propsData);
|
||||
} else {
|
||||
instance = createVNode(ImgPreview, propsData);
|
||||
render(instance, container);
|
||||
document.body.appendChild(container);
|
||||
}
|
||||
return instance.component?.exposed;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user