Skip to content

[Bug]: 在vite-vue3项目中,插件grid-line配置follow为true时,控制台提示getCanvasCenter未定义,但程序能正常运行。 #7218

@huahua123-cloud

Description

@huahua123-cloud

Describe the bug / 问题描述

Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'getCanvasCenter')
    at mU.getCanvasCenter (g6.min.js:79:71804)
    at ZB.followZoom (g6.min.js:71:58198)
    at ZB.onTransform (g6.min.js:71:58593)
    at a2 (g6.min.js:66:45643)
    at t2.emit (g6.min.js:66:45656)
    at XH (g6.min.js:79:8002)
    at vU.<anonymous> (g6.min.js:79:54039)
    at Generator.next (<anonymous>)
    at g6.min.js:1:33441
    at new Promise (<anonymous>)

代码如下,modelStore是使用pinia建立的共享数据仓库:

onMounted(async () => {
    // 默认配置,可在具体的画布中更改
    modelStore.graph = markRaw(
        new G6.Graph({
            container: container.value,
            behaviors: ['drag-canvas', 'zoom-canvas'],
            plugins: [
                { type: 'grid-line', key: 'GridLine', follow: true }
            ]
        })
    )
    modelStore.graph.fitCenter()
    useDiagramEvents(modelStore.graph as Graph)

    const changeGraphSize = debounce((width: number, height: number) => modelStore.graph?.setSize(width, height), 100)
    resizeObserver = new ResizeObserver((entries) => {
        for (let entry of entries) {
            changeGraphSize(entry.contentRect.width, entry.contentRect.height)
        }
    })
    resizeObserver.observe(containerBox.value) // 监听指定的容器

    modelStore.graph.render()
})

Reproduction link / 复现链接

No response

Steps to Reproduce the Bug or Issue / 重现步骤

No response

Version / 版本

🆕 5.x

OS / 操作系统

  • macOS
  • Windows
  • Linux
  • Others / 其他

Browser / 浏览器

  • Chrome
  • Edge
  • Firefox
  • Safari (Limited support / 有限支持)
  • IE (Nonsupport / 不支持)
  • Others / 其他

Metadata

Metadata

Assignees

No one assigned

    Labels

    need improvementLack of information or incorrect formatwaiting for authorFurther information is requested from the author.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions