g6-extension-vue

Using Vue Component to Define Your G6 Graph Node
35,130 10
Install
npm install g6-extension-vue
Latest Version:0.1.0
Vue:2 · 3
License:MIT
Last Updated:Aug 18, 2026
Links: GitHub  ·  npm
Maintainer: childqjj

G6 Extension Vue

English | 中文

NPM Package Build Size NPM Downloads

This extension allows you to define G6 nodes using Vue components. It's inspired by @antv/g6-extension-react.

Features

  • 🎯 Vue Node Support: Use Vue components as G6 nodes
  • 🔧 Vue 2/3 Compatible: Support both Vue 2 and Vue 3
  • 📦 TypeScript Support: Full type definitions

Usage

1. Install

npm install g6-extension-vue
# or
yarn add g6-extension-vue
# or
pnpm add g6-extension-vue

2. Import and Register

import { onMounted, defineComponent } from 'vue';
import { VueNode } from 'g6-extension-vue';
import { ExtensionCategory, register } from '@antv/g6';

register(ExtensionCategory.NODE, 'vue', VueNode); // or in onMounted

3. Define Node

Vue Composition API:

import { defineComponent, h } from 'vue';
export default defineComponent({
  props: {
    data: {
      type: Object,
      default: () => ({}),
    },
  },
  setup(props) {
    return () => {
      return h(
        'div',
        {
          class: 'vue-node',
        },
        props.data.label,
      );
    };
  },
});

Vue Functional component:

export default function VueNode(props) {
  return <div class="vue-node">
    {props.data.label}
  </div>

4. Use Node

const graph = new Graph({
  // ... other options
  node: {
    type: 'vue',
    style: {
      component: (data) => <VueNode data={Object.assign({}, data)} />, // new object to trigger effect
    },
  },
});

Q&A

1. Why the watch props is not working? (vue3)

VueNode will refresh when g6 node property changes.(hover、click、drag、etc.) And make sure that the node data is reactive.

✅ Correct Examples:
// Method 1: Create new object with spread operator
const graph = new Graph({
  node: {
    type: 'vue',
    style: {
      component: (data) => <VueNode data={{ ...data }} />, // Creates new object
    },
  },
});

// Method 2: Use Object.assign to create new object
const graph = new Graph({
  node: {
    type: 'vue',
    style: {
      component: (data) => <VueNode data={Object.assign({}, data)} />, // Creates new object
    },
  },
});
❌ Incorrect Examples:
// DON'T: Direct reference - won't trigger reactivity
const graph = new Graph({
  node: {
    type: 'vue',
    style: {
      component: (data) => <VueNode data={data} />, // Direct reference
    },
  },
});

// DON'T: Nested property direct reference
const graph = new Graph({
  node: {
    type: 'vue',
    style: {
      component: (data) => <VueNode data={data.data} />, // Direct nested reference
    },
  },
});

Important Note: Non-reactive objects need new object references to trigger side effects. When you pass the same object reference, Vue won't know the data has changed and won't re-render the component.

Development

# Install dependencies
npm install

# Development mode
npm run dev

# Build
npm run build

# Test
npm run test

# Lint
npm run lint

Compatibility

  • Vue 2.6+
  • Vue 3.0+
  • G6 5.0+

License

MIT License @Child-qjj

Contributing

Welcome to submit Issues and Pull Requests!

Related Packages

sgs-node

sgs node

9,429
pyz-knowledge-graph-vue

Vue 3 知识图谱可视化组件,基于 AntV G6

3,185
@roots/bud-vue

Adds @vue/vue support to @roots/bud projects

30,319 346
express-vue

Vue rendering engine for Express.js

15,239 1,297
poke-ball

vuejs application generator 帮助开发人员快速生成一个vuejs项目,同时支持该项目模...

1,632

Version History

Version Released License
0.1.0 MIT
0.0.16 MIT
0.0.15 MIT
0.0.14 MIT
0.0.13 MIT
Pre-releases (2)
Version Released License
0.0.11-beta MIT
0.0.1-beta MIT