Sanakey
2024-08-02 1ba88a00d3c7bb0f16a73feaa5ffcf7c1635e0ea
提交 | 用户 | age
bab28a 1 import { isClient } from '@/utils/is';
b7c7c4 2 import { createVNode, render } from 'vue';
25699c 3 import ImgPreview from './Functional.vue';
4 import type { Options, Props } from './typing';
b7c7c4 5
305630 6 let instance: ReturnType<typeof createVNode> | null = null;
b7c7c4 7 export function createImgPreview(options: Options) {
J 8   if (!isClient) return;
9   const propsData: Partial<Props> = {};
10   const container = document.createElement('div');
e23bd2 11   Object.assign(propsData, { show: true, index: 0, scaleStep: 100 }, options);
b7c7c4 12
25699c 13   if (instance?.component) {
14     // 存在实例时,更新props
15     Object.assign(instance.component.props, propsData);
16   } else {
17     instance = createVNode(ImgPreview, propsData);
18     render(instance, container);
19     document.body.appendChild(container);
20   }
e23bd2 21   return instance.component?.exposed;
b7c7c4 22 }