|
@@ -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;
|
|
|
}
|