@antv/x6 插件引入的时候报TypeError: Cannot read properties of undefined (reading ‘ToolItem‘)的解决方法

1、先上一个图:

开始引入@antv/x6,初始化的时候,一切正常。

然后引入插件的时候,就报上面的错了。

然后vite这边也有人提出了:

https://github.com/vitejs/vite/issues/3413

2、修改vite配制解决:

optimizeDeps: {
      exclude: [
        '@antv/x6',
        '@antv/x6-plugin-history',
        '@antv/x6-plugin-keyboard',
        '@antv/x6-plugin-selection',
        '@antv/x6-plugin-snapline',
        '@antv/x6-plugin-clipboard',
        '@antv/x6-plugin-keyboard',
      ],
    },

这样加了排除以后,就按需引相应的插件就可以。

3、引入插件:

比如用一用缩放的功能

import { Transform } from '@antv/x6-plugin-transform';
const container = new Graph({
      container: document.getElementById('container'),
      grid: true,
      width,
      height,
    });

    dvChild.use(
      new Transform({
        resizing: true,
        rotating: true,
      }),
    );

dvChild.addNode({
      shape: 'image',
      x: 320,
      y: 120,
      width: 200,
      height: 180,
      imageUrl:
        'https://gips1.baidu.com/it/u=2109130335,2323458671&fm=3028&app=3028&f=PNG&fmt=auto&q=100&size=f1296_198',
    });

最后上一张效果图:

其它的插件,一样的使用,相当可以。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值