Skip to content

Commit e092d49

Browse files
wangyiteng_vboyongjiong
authored andcommitted
fix: 修复vue2环境中引用vue-dimi不提供render方法导致vue2报引入错误问题
1 parent 00a30f1 commit e092d49

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

packages/vue-node-registry/src/teleport.ts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { BaseNodeModel, GraphModel } from '@logicflow/core'
22
import {
33
defineComponent,
44
h,
5-
render,
5+
createApp,
66
reactive,
77
isVue3,
88
Teleport,
@@ -11,6 +11,7 @@ import {
1111
} from 'vue-demi'
1212

1313
let active = false
14+
const appInstances = new Map<string, InstanceType<any>>()
1415
const items = reactive<{ [key: string]: any }>({})
1516

1617
export function connect(
@@ -36,9 +37,14 @@ export function connect(
3637
}
3738
}
3839

39-
export function disconnect(id: string) {
40+
export function disconnect(id: string, flowId: string) {
4041
if (active) {
4142
delete items[id]
43+
const app = appInstances.get(flowId)
44+
if (app) {
45+
app.unmount()
46+
appInstances.delete(flowId)
47+
}
4248
}
4349
}
4450

@@ -99,9 +105,18 @@ export function createTeleportContainer(
99105
// 获取 Teleport 组件
100106
const TeleportContainer = getTeleport()
101107

102-
// 创建 Teleport 组件的虚拟节点,传入 flowId
103-
const teleportVNode = h(TeleportContainer, { flowId })
108+
// 不重新创建 Teleport 容器组件
109+
if (appInstances.has(flowId)) {
110+
return
111+
}
112+
113+
// ✅ 1. 创建独立容器放到目标容器中
114+
const mountPoint = document.createElement('div')
115+
container.appendChild(mountPoint)
116+
117+
// ✅ 2. 创建并挂载 Vue 应用到新容器
118+
const app = createApp(TeleportContainer, { flowId })
119+
app.mount(mountPoint)
104120

105-
// 渲染到指定容器中
106-
render(teleportVNode, container)
121+
appInstances.set(flowId, app)
107122
}

packages/vue-node-registry/src/view.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ export class VueNodeView extends HtmlNode {
100100

101101
unmount() {
102102
if (isActive()) {
103-
disconnect(this.targetId())
103+
disconnect(this.targetId(), this.props.graphModel.flowId!)
104104
}
105105
this.unmountVueComponent()
106106
}

0 commit comments

Comments
 (0)