{"id":559,"date":"2025-11-27T06:59:24","date_gmt":"2025-11-26T22:59:24","guid":{"rendered":"https:\/\/www.idcyz.com\/blog\/?p=559"},"modified":"2025-11-27T06:59:24","modified_gmt":"2025-11-26T22:59:24","slug":"%e7%bb%93%e5%90%88-antv-g6-%e5%92%8c-vue-%e9%9c%80%e8%a6%81%e5%a4%9a%e5%b0%91%e6%ad%a5%e9%aa%a4%e6%89%8d%e8%83%bd%e5%ae%9e%e7%8e%b0%e5%9b%be%e6%95%b0%e6%8d%ae%e5%8f%af%e8%a7%86%e5%8c%96","status":"publish","type":"post","link":"https:\/\/www.idcyz.com\/blog\/559.html","title":{"rendered":"\u7ed3\u5408 AntV G6 \u548c Vue \u9700\u8981\u591a\u5c11\u6b65\u9aa4\u624d\u80fd\u5b9e\u73b0\u56fe\u6570\u636e\u53ef\u89c6\u5316"},"content":{"rendered":"<p><p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/www.idcyz.com\/blog\/wp-content\/uploads\/2025\/07\/JxG67f9.jpg\" alt=\"\u7ed3\u5408 AntV G6 \u548c Vue \u9700\u8981\u591a\u5c11\u6b65\u9aa4\u624d\u80fd\u5b9e\u73b0\u56fe\u6570\u636e\u53ef\u89c6\u5316\" title=\"\u7ed3\u5408 AntV G6 \u548c Vue \u9700\u8981\u591a\u5c11\u6b65\u9aa4\u624d\u80fd\u5b9e\u73b0\u56fe\u6570\u636e\u53ef\u89c6\u5316\"><\/p>\n<p><h3>antv g6 vue \u7b80\u4ecb<\/h3>\n<\/p>\n<p>  AntV G6 \u662f Ant Design \u56e2\u961f\u63a8\u51fa\u7684\u4e00\u6b3e\u56fe\u53ef\u89c6\u5316\u5e93\uff0c\u4e13\u6ce8\u4e8e\u56fe\u7ed3\u6784\u6570\u636e\u7684\u8868\u73b0\u3002\u800c Vue.js \u662f\u4e00\u4e2a\u6e10\u8fdb\u5f0f\u7684 JavaScript \u6846\u67b6\uff0c\u65e8\u5728\u6784\u5efa\u7528\u6237\u754c\u9762\u3002\u5c06\u8fd9\u4e24\u8005\u7ed3\u5408\uff0c\u53ef\u4ee5\u7528 Vue \u7684\u4f18\u96c5\u8bed\u6cd5\u6765\u521b\u5efa\u590d\u6742\u7684\u56fe\u8868\uff0c\u63d0\u5347\u5f00\u53d1\u6548\u7387\u548c\u53ef\u7ef4\u62a4\u6027\u3002<\/p>\n<\/p>\n<p>\n<h3>AntV G6 \u7684\u4f18\u52bf<\/h3>\n<\/p>\n<p>  AntV G6 \u63d0\u4f9b\u4e86\u591a\u79cd\u529f\u80fd\uff0c\u5982\uff1a<\/p>\n<ul>\n<li>\u4f18\u79c0\u7684\u6027\u80fd\uff1a\u65e0\u8bba\u662f\u5927\u6570\u636e\u91cf\u7684\u56fe\u8fd8\u662f\u590d\u6742\u7684\u4ea4\u4e92\uff0cG6 \u90fd\u80fd\u4fdd\u6301\u826f\u597d\u7684\u6027\u80fd\u3002<\/li>\n<li>\u4e30\u5bcc\u7684\u5e03\u5c40\uff1a\u652f\u6301\u591a\u79cd\u56fe\u5e03\u5c40\uff0c\u5982\u529b\u5bfc\u5411\u3001\u6811\u5f62\u3001\u5706\u5f62\u7b49\uff0c\u8ba9\u53ef\u89c6\u5316\u66f4\u76f4\u89c2\u3002<\/li>\n<li>\u7075\u6d3b\u7684\u5b9a\u5236\u6027\uff1a\u53ef\u4ee5\u81ea\u5b9a\u4e49\u8282\u70b9\u3001\u8fb9\u7684\u6837\u5f0f\uff0c\u6ee1\u8db3\u4e0d\u540c\u7684\u4e1a\u52a1\u9700\u6c42\u3002<\/li>\n<\/ul>\n<p>  G6 \u4f7f\u5f97\u7528\u6237\u5728\u56fe\u8868\u8868\u73b0\u4e0a\u66f4\u52a0\u7075\u6d3b\uff0c\u53ef\u4ee5\u6839\u636e\u5177\u4f53\u9700\u6c42\u53bb\u8c03\u6574\u6bcf\u4e00\u4e2a\u7ec6\u8282\u3002<\/p>\n<\/p>\n<p>\n<h3>Vue \u7684\u4f18\u70b9<\/h3>\n<\/p>\n<p>  Vue.js \u7684\u8bbe\u8ba1\u4f7f\u5176\u80fd\u591f\u5f88\u597d\u5730\u4e0e\u5176\u4ed6\u5e93\u6216\u73b0\u6709\u9879\u76ee\u8fdb\u884c\u96c6\u6210\u3002\u5b83\u7684\u4f18\u70b9\u5305\u62ec\uff1a<\/p>\n<ul>\n<li>\u6570\u636e\u53cc\u5411\u7ed1\u5b9a\uff1a\u5904\u7406\u6570\u636e\u53d8\u5316\u66f4\u52a0\u7b80\u5355\uff0c\u5b9e\u65f6\u6e32\u67d3\u89c6\u56fe\uff0c\u5f88\u597d\u5730\u89e3\u51b3\u4e86 DOM \u64cd\u4f5c\u7684\u590d\u6742\u6027\u3002<\/li>\n<li>\u7ec4\u4ef6\u5316\uff1a\u5c06 UI \u5212\u5206\u4e3a\u591a\u4e2a\u7ec4\u4ef6\uff0c\u65e2\u63d0\u9ad8\u4e86\u4ee3\u7801\u7684\u53ef\u590d\u7528\u6027\uff0c\u53c8\u4f7f\u9879\u76ee\u66f4\u5177\u7ed3\u6784\u6027\u3002<\/li>\n<li>\u53cb\u597d\u7684\u793e\u533a\u4e0e\u6587\u6863\uff1a\u6709\u5927\u91cf\u7684\u793e\u533a\u8d44\u6e90\u548c\u6587\u6863\u652f\u6301\uff0c\u5feb\u901f\u4e0a\u624b\u3002<\/li>\n<\/ul>\n<p>  \u5229\u7528 Vue \u7684\u4f18\u52bf\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u5728\u66f4\u9ad8\u5c42\u6b21\u4e0a\u628a\u63a7\u6574\u4f53\u67b6\u6784\u3002<\/p>\n<\/p>\n<p>\n<h3>\u5982\u4f55\u5728 Vue \u4e2d\u4f7f\u7528 AntV G6<\/h3>\n<\/p>\n<p>  \u628a G6 \u96c6\u6210\u5230 Vue \u9879\u76ee\u4e2d\u5e76\u4e0d\u590d\u6742\u3002\u4f60\u53ea\u9700\u51e0\u4e2a\u6b65\u9aa4\uff1a<\/p>\n<p><pre><code><\/p>\r\n<p>  \/\/ \u5b89\u88c5 G6<\/p>\r\n<p>  npm install @antv\/g6 --save<\/p>\r\n<p>  <\/code><\/pre>\n<\/p>\n<p>  \u5728\u4f60\u7684 Vue \u7ec4\u4ef6\u4e2d\u5f15\u5165 G6\uff1a<\/p>\n<p><pre><code><\/p>\r\n<p>  import G6 from '@antv\/g6';<\/p>\r\n<p>  <\/code><\/pre>\n<\/p>\n<p>  \u63a5\u4e0b\u6765\uff0c\u5728 created \u6216 mounted \u751f\u547d\u5468\u671f\u4e2d\u521b\u5efa\u56fe\uff1a<\/p>\n<p><pre><code><\/p>\r\n<p>  mounted() {<\/p>\r\n<p>      const graph = new G6.Graph({<\/p>\r\n<p>          container: 'container',<\/p>\r\n<p>          width: 800,<\/p>\r\n<p>          height: 600,<\/p>\r\n<p>          modes: {<\/p>\r\n<p>              default: ['drag-node', 'zoom-canvas', 'click-select'],<\/p>\r\n<p>          },<\/p>\r\n<p>          defaultNode: {<\/p>\r\n<p>              shape: 'circle',<\/p>\r\n<p>              size: [60],<\/p>\r\n<p>              style: {<\/p>\r\n<p>                  fill: '#C6E5FF',<\/p>\r\n<p>                  stroke: '#5B8FF9',<\/p>\r\n<p>              },<\/p>\r\n<p>          },<\/p>\r\n<p>          defaultEdge: {<\/p>\r\n<p>              style: {<\/p>\r\n<p>                  stroke: '#A3B1C6',<\/p>\r\n<p>              },<\/p>\r\n<p>          },<\/p>\r\n<p>      });<\/p>\r\n<p>      graph.data(data);<\/p>\r\n<p>      graph.render();<\/p>\r\n<p>  }<\/p>\r\n<p>  <\/code><\/pre>\n<\/p>\n<p>\n<h3>\u5982\u4f55\u5904\u7406\u56fe\u6570\u636e<\/h3>\n<\/p>\n<p>  G6 \u5904\u7406\u6570\u636e\u7684\u65b9\u5f0f\u76f8\u5bf9\u7b80\u5355\u3002\u4e00\u822c\u4f60\u53ef\u4ee5\u4f7f\u7528\u4e00\u4e2a JSON \u683c\u5f0f\u7684\u6570\u636e\u5bf9\u8c61\u6765\u8868\u793a\u56fe\u7684\u6570\u636e\u7ed3\u6784\u3002\u4f8b\u5982\uff1a<\/p>\n<p><pre><code><\/p>\r\n<p>  const data = {<\/p>\r\n<p>      nodes: [<\/p>\r\n<p>          { id: 'node1', label: '\u8282\u70b91' },<\/p>\r\n<p>          { id: 'node2', label: '\u8282\u70b92' },<\/p>\r\n<p>      ],<\/p>\r\n<p>      edges: [<\/p>\r\n<p>          { source: 'node1', target: 'node2' },<\/p>\r\n<p>      ],<\/p>\r\n<p>  };<\/p>\r\n<p>  <\/code><\/pre>\n<\/p>\n<p>  \u7136\u540e\u5728\u521b\u5efa\u56fe\u4e4b\u540e\u6e32\u67d3\u51fa\u8fd9\u79cd\u6570\u636e\u7ed3\u6784\uff0c\u53ef\u4ee5\u66f4\u597d\u7684\u5b9e\u73b0\u903b\u8f91\u548c\u5c55\u793a\u3002<\/p>\n<\/p>\n<p>\n<h3>\u5e38\u89c1\u95ee\u9898\u89e3\u7b54<\/h3>\n<\/p>\n<p>  <b>1. AntV G6 \u548c\u5176\u4ed6\u56fe\u53ef\u89c6\u5316\u5e93\u7684\u533a\u522b\u662f\u4ec0\u4e48\uff1f<\/b><\/p>\n<p>  AntV G6 \u7279\u522b\u5173\u6ce8\u56fe\u7ed3\u6784\u6570\u636e\uff0c\u4f18\u5316\u4e86\u6027\u80fd\u548c Layout \u9009\u9879\u3002\u4e0e\u5176\u4ed6\u5e93\u76f8\u6bd4\uff0cG6 \u66f4\u52a0\u6ce8\u91cd\u4e8e\u590d\u6742\u7684\u56fe\u5f62\u5173\u7cfb\u548c\u5206\u6790\u3002<\/p>\n<p>  <b>2. \u7528 Vue.js \u7ed8\u5236\u56fe\u8868\u7684\u4f18\u7f3a\u70b9\u662f\u4ec0\u4e48\uff1f<\/b><\/p>\n<p>  \u4f18\u70b9\u662f\u6570\u636e\u53cc\u5411\u7ed1\u5b9a\u548c\u7ec4\u4ef6\u5316\uff0c\u5f00\u53d1\u6548\u7387\u9ad8\uff0c\u800c\u7f3a\u70b9\u5728\u4e8e\u4e0e\u539f\u751f JS \u7684\u96c6\u6210\u53ef\u80fd\u7a0d\u663e\u590d\u6742\uff0c\u7279\u522b\u662f\u5728\u5904\u7406\u5927\u578b\u56fe\u5f62\u65f6\u3002<\/p>\n<p>  <b>3. \u5982\u4f55\u8c03\u8bd5\u548c\u4f18\u5316 G6 \u56fe\u8868\uff1f<\/b><\/p>\n<p>  \u53ef\u4ee5\u4f7f\u7528 Chrome DevTools \u8fdb\u884c\u6027\u80fd\u5206\u6790\uff0c\u5e76\u5229\u7528 G6 \u63d0\u4f9b\u7684\u5185\u7f6e\u65b9\u6cd5\uff0c\u5982 `graph.update()` \u8fdb\u884c\u5c40\u90e8\u66f4\u65b0\uff0c\u907f\u514d\u91cd\u7ed8\u6574\u5f20\u56fe\u3002<\/p>\n<\/p>\n<p>\n<h3>\u603b\u7ed3<\/h3>\n<\/p>\n<p>  AntV G6 \u548c Vue.js \u7684\u7ed3\u5408\u4e3a\u5f00\u53d1\u8005\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u53ef\u89c6\u5316\u5de5\u5177\u3002\u901a\u8fc7\u4e0a\u8ff0\u65b9\u6cd5\u548c\u793a\u4f8b\uff0c\u53ef\u4ee5\u5feb\u901f\u6784\u5efa\u51fa\u529f\u80fd\u4e30\u5bcc\u4e14\u6027\u80fd\u4f18\u8d8a\u7684\u56fe\u8868\uff0c\u5e76\u6ee1\u8db3\u4e0d\u540c\u573a\u666f\u7684\u9700\u6c42\u3002\u65e0\u8bba\u662f\u6570\u636e\u53ef\u89c6\u5316\u7684\u521d\u5b66\u8005\u8fd8\u662f\u6709\u7ecf\u9a8c\u7684\u5f00\u53d1\u8005\uff0c\u90fd\u80fd\u5728\u8fd9\u4e2a\u7ec4\u5408\u4e2d\u627e\u5230\u5408\u9002\u7684\u5b9e\u73b0\u8def\u5f84\u3002<\/p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>antv g6 vue \u7b80\u4ecb AntV G6 \u662f Ant Design \u56e2\u961f\u63a8\u51fa\u7684\u4e00\u6b3e\u56fe\u53ef\u89c6\u5316\u5e93\uff0c\u4e13\u6ce8\u4e8e\u56fe\u7ed3\u6784\u6570\u636e\u7684\u8868\u73b0\u3002\u800c Vue.js \u662f\u4e00\u4e2a\u6e10\u8fdb\u5f0f\u7684 JavaScript \u6846\u67b6\uff0c\u65e8\u5728\u6784\u5efa\u7528\u6237\u754c\u9762\u3002\u5c06\u8fd9\u4e24\u8005\u7ed3\u5408\uff0c\u53ef\u4ee5\u7528 Vue \u7684\u4f18\u96c5\u8bed&#8230;<\/p>\n","protected":false},"author":1,"featured_media":560,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[294,293,258],"topic":[],"class_list":["post-559","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-jiushu","tag-antv","tag-g","tag-vue"],"_links":{"self":[{"href":"https:\/\/www.idcyz.com\/blog\/wp-json\/wp\/v2\/posts\/559","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.idcyz.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.idcyz.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.idcyz.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.idcyz.com\/blog\/wp-json\/wp\/v2\/comments?post=559"}],"version-history":[{"count":1,"href":"https:\/\/www.idcyz.com\/blog\/wp-json\/wp\/v2\/posts\/559\/revisions"}],"predecessor-version":[{"id":562,"href":"https:\/\/www.idcyz.com\/blog\/wp-json\/wp\/v2\/posts\/559\/revisions\/562"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.idcyz.com\/blog\/wp-json\/wp\/v2\/media\/560"}],"wp:attachment":[{"href":"https:\/\/www.idcyz.com\/blog\/wp-json\/wp\/v2\/media?parent=559"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.idcyz.com\/blog\/wp-json\/wp\/v2\/categories?post=559"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.idcyz.com\/blog\/wp-json\/wp\/v2\/tags?post=559"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.idcyz.com\/blog\/wp-json\/wp\/v2\/topic?post=559"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}