#5062·X6

为什么使用 cdn 和使用 npm 包导入的行为会不同?

Author: Dedicatus546Created Apr 27, 2026Updated Aug 3, 2026
Labelswaiting for maintainer

问题描述

同样监听 cell:mouseenter ,npm 引入的正常触发, cdn 引入的不触发,这是什么奇怪的 bug ,是我使用的方式有问题吗。。。

代码:

javascript
const graph = new Graph({
  container: document.getElementById("container") as HTMLElement,
  width: 800,
  height: 600,
  grid: true,
});

graph.addNode({
  shape: "image",
  x: 320,
  y: 120,
  width: 94,
  height: 28,
  imageUrl:
    "https://gw.alipayobjects.com/os/s/prod/antv/assets/image/logo-with-text-73b8a.svg",
});

graph.on("cell:mouseenter", (data) => {
  console.log("mouseenter", data);
});
graph.on("cell:mouseleave", (data) => {
  console.log("mouseleave", data);
});

其中 cdn 引入使用 X6.Graph ,npm 引入使用 import { Graph } from "@antv/x6"

重现链接

https://codesandbox.io/p/sandbox/g9v9pm

重现步骤

  1. 进入页面
  2. 移入 cdn 下的 antv 节点,没有弹出 alert
  3. 移入 npm 下的 antv 节点,弹出 alert

预期行为

cdn 引入的 antv 节点也应该弹出 alert

平台

  • 操作系统: [Windows]
  • 网页浏览器: [Google Chrome]
  • X6 版本: [3.1.7]

屏幕截图或视频(可选但最好有)

No response

补充说明(可选)

No response