Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vue 节点数据缓存问题 #4054

Open
Niefee opened this issue Nov 29, 2023 · 9 comments · May be fixed by #4500
Open

vue 节点数据缓存问题 #4054

Niefee opened this issue Nov 29, 2023 · 9 comments · May be fixed by #4500

Comments

@Niefee
Copy link

Niefee commented Nov 29, 2023

Describe the bug

const items = reactive<{ [key: string]: any }>({})

以上代码,在router 页面缓存的情况下,
我用dnd跟@antv/x6-vue-shape结合,这里items 在 mount的时候没有清除,每次都把之前的累计进来,导致我拖拽节点,会赋值几个。
aa

能不能提供一个方法,可以清除这个变量数据

  • OS: [e.g. macOS, Windows, Linux]
  • Browser: [e.g. Chrome, Safari, Firefox]
  • Version: [e.g. 2.11.1]

1

@Niefee
Copy link
Author

Niefee commented Nov 29, 2023

mx_screencap_20231129_203501

mount多少次,就重复节点多个节点,vue页面路由是会被缓存的,每次进入查询参数有变化,但是节点数据是没有,通过dnd添加就会重复

@lloydzhou
Copy link
Contributor

这个teleport里面的items是按照id存所有的节点对象的。按道理不会出现重复。

这里使用的是${this.graph.view.cid}:${this.cell.id}

这里出现重复,原因可能是,你在dnd操作过程中clone的时候,id没有变化。导致重复了。
或者x6的节点没有正确触发unmount方法。

@lloydzhou
Copy link
Contributor

或许确实应该在getTeleport返回的节点里面写一个onUnmounted

image

@Niefee
Copy link
Author

Niefee commented Nov 30, 2023

@lloydzhou vue-router页面是是走缓存的,但是切换query,就会触发mount,就是mount多少次,拖拽新节点,就会重复多少次。是否会添加onUnmounted,是什么时候更新

@lloydzhou
Copy link
Contributor

我感觉还是有一点问题:
Teleport对应的container这里使用的是 HTMLDivElement没有使用id之类的,按道理讲,重新走mount之后,生成的应该是新的节点不会重复吧?

@Niefee
Copy link
Author

Niefee commented Nov 30, 2023

import { register } from '@antv/x6-vue-shape';
register({
    shape: 'custom-vue-node',
    width: 100,
    height: 100,
    component: markRaw(
        renderFn({
            setup(props: any, context: any) {
                const divEl = ref();
                return () => h('div', { ref: divEl, style: 'background: red;margin: 10px;' }, '=====test=====');
            },
        }),
    ),
});

 dnd.value = new Dnd({
        target: graph.value,
        dndContainer: dndBox.value,
        getDropNode(node: any, _options: any) {
            nodeIndex.value = nodeIndex.value + 1;
            const { x, y } = node.position();
            const { width, height } = node.size();
            return graph.value.createNode({
                id: `node-${node.data.data.tableName}`,
                x,
                y,
                width: width,
                height: height,
                ports: ports.value,
                data: {
                    ...node.data,
                    nodeIndex: nodeIndex.value,
                },
                shape: 'custom-vue-node',
            });
        },
    });

@lloydzhou 核心代码就是这样,拖拽到画布,每次mount,之前都会重复节点

@Niefee
Copy link
Author

Niefee commented Nov 30, 2023

#4064 (comment) @lloydzhou 麻烦也看看,每次mount也报port id重复问题

@yuxinerdaluobo
Copy link

yuxinerdaluobo commented Dec 28, 2023

想问一下这个问题解决了吗?

@Niefee
Copy link
Author

Niefee commented Jan 3, 2024

没有,热更新还是经常报错 @yuxinerdaluobo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants