antvis/G6

在vue中graph.on('canvas:dblclick',fn)不生效 #4855

padeyao4 posted onGitHub

Describe the bug

在vue中graph.on('dblclick',fn) 有效果 graph.on('canvas:dblclick',fn) 不生效

Your Example Website or App

xxx

Steps to Reproduce the Bug or Issue

正常创建 vue 项目 cnpm init vue@latest cnpm i @antv/g6 --save

<script setup lang="ts">
import { Graph } from '@antv/g6';
import { onMounted, ref } from 'vue'

let root = ref<HTMLElement>()
let graph = ref<Graph>()

onMounted(() => {
  const data = {
    // 点集
    nodes: [
      {
        id: 'node1',
        x: 100,
        y: 200,
      },
      {
        id: 'node2',
        x: 300,
        y: 200,
      },
    ],
    // 边集
    edges: [
      // 表示一条从 node1 节点连接到 node2 节点的边
      {
        source: 'node1',
        target: 'node2',
      },
    ],
  };
  graph.value = new Graph({
    container: root.value!,
  })
  graph.value.on('canvas:dblclick', () => {
    console.log('canvas:dblclick')
  })
  graph.value.on('node:dblclick', () => {
    console.log('node:dblclick')
  })
  graph.value.on('dblclick', () => {
    console.log('dblclick')
  })
  graph.value.read(data)
})

</script>

<template>
  <div ref="root" style="width: 100% ; height: 800px; background-color: antiquewhite"></div>
</template>

Expected behavior

正常情况下 双击canvas打印信息

实际情况 双击canvas没有效果

Screenshots or Videos

No response

Platform

  • OS: [Linux]
  • Browser: [Edge]
  • Version: [4.8.21]

Additional context

No response


给个在线复现 demo 吧

posted by Yanyan-Wang over 1 year ago

我也遇到了这个问题,经过反复的调试,初步判断可能是因为 vue proxy代理的问题,在绑定graph的事件时 使用toRaw() 将graph转换为原始对象可以暂时解决这个问题

posted by suzukaovo over 1 year ago

测试一下,只要执行了 graph.render() 或 graph.changeSize() , graph.on('canvas:dblclick',fn) 就会失效。 测试的例子 https://github.com/padeyao4/vue-g6-canvas-debug.git

posted by padeyao4 over 1 year ago

在官网中测试没发现这个问题。试试楼上的解决方案

posted by Yanyan-Wang over 1 year ago

我找到vue和g6的正确做法来了,多谢

posted by padeyao4 over 1 year ago

我找到vue和g6的正确做法来了,多谢

所以是怎么做的

posted by 584sentiment over 1 year ago

我找到vue和g6的正确做法来了,多谢

所以是怎么做的

试试 shallowRef 代替 ref

posted by padeyao4 over 1 year ago

我找到vue和g6的正确做法来了,多谢

所以是怎么做的

试试 shallowRef 代替 ref

正解 点赞👍

posted by SKT1yang about 1 year ago

Fund this Issue

$0.00
Funded

Pull requests