Vue-cli3生成的Vue項(xiàng)目加載Mxgraph方法示例
使用Vue-cli3生成Vue項(xiàng)目,并等待項(xiàng)目創(chuàng)建成功。
vue create [項(xiàng)目名]
安裝mxgraph。
cnpm install mxgraph --save
安裝exports-loader。
cnpm install exports-loader --save
安裝script-loader。
cnpm install script-loader --save
在項(xiàng)目根目錄新建vue.config.js文件。
將以下內(nèi)容復(fù)制到vue.config.js文件中。
const path = require('path'); function resolve(dir) { return path.join(__dirname, dir); } module.exports = { publicPath: './', outputDir: 'dist', lintOnSave: true, chainWebpack: (config) => { config.module .rule('') .test(/mxClient\.js$/) .use('exports-loader') .loader('exports-loader?mxClient,mxGraphModel,mxActor,mxShape,mxEventObject,mxGraph,mxPrintPreview,mxEventSource,mxRectangle,mxVertexHandler,mxMouseEvent,mxGraphView,mxImage,mxGeometry,mxRubberband,mxKeyHandler,mxDragSource,mxGraphModel,mxEvent,mxUtils,mxWindow,mxEvent,mxCodec,mxCell,mxConstants,mxPoint,mxGraphHandler,mxCylinder,mxCellRenderer,mxEvent,mxUndoManager') .end(); config.resolve.alias .set('@', resolve('src')) .set('@assets', resolve('src/assets')); // 按這種格式.set('', resolve('')) 自己添加 } };
修改HelloWorld.vue,替換為以下內(nèi)容。
<template> <div ref="graph_container"></div> </template> <script> import { mxGraph } from 'mxgraph/javascript/mxClient'; export default { name: 'HelloWorld', props: { msg: String }, mounted() { // Creates the graph inside the given container var graph = new mxGraph(this.$refs.graph_container); // Gets the default parent for inserting new cells. This // is normally the first child of the root (ie. layer 0). var parent = graph.getDefaultParent(); // Adds cells to the model in a single step graph.getModel().beginUpdate(); try { let v1 = graph.insertVertex(parent, null, 'Hello,', 20, 20, 80, 30); let v2 = graph.insertVertex(parent, null, 'World!', 200, 150, 80, 30); graph.insertEdge(parent, null, '', v1, v2); } finally { // Updates the display graph.getModel().endUpdate(); } } }; </script> <!-- Add "scoped" attribute to limit CSS to this component only --> <style scoped> h3 { margin: 40px 0 0; } ul { list-style-type: none; padding: 0; } li { display: inline-block; margin: 0 10px; } a { color: #42b983; } </style>
運(yùn)行項(xiàng)目,查看效果。此Demo的源碼可以查看
到此這篇關(guān)于Vue-cli3生成的Vue項(xiàng)目加載Mxgraph方法示例的文章就介紹到這了,更多相關(guān)Vue項(xiàng)目加載Mxgraph內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Vue實(shí)戰(zhàn)之vue登錄驗(yàn)證的實(shí)現(xiàn)代碼
本篇文章主要介紹了Vue實(shí)戰(zhàn)之vue登錄的實(shí)現(xiàn)代碼,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-10-10詳解vue+axios給開發(fā)環(huán)境和生產(chǎn)環(huán)境配置不同的接口地址
這篇文章主要介紹了詳解vue+axios給開發(fā)環(huán)境和生產(chǎn)環(huán)境配置不同的接口地址,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-08-08vite.config.ts配置之自動(dòng)導(dǎo)入element-puls方式
這篇文章主要介紹了vite.config.ts配置之自動(dòng)導(dǎo)入element-puls方式,具有很好的參考價(jià)值,希望對大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-10-10vue?Router(v3.x)?路由傳參的三種方式場景分析
vue?路由傳參的使用場景一般都是應(yīng)用在父路由跳轉(zhuǎn)到子路由時(shí),攜帶參數(shù)跳轉(zhuǎn),傳參方式可劃分為?params?傳參和?query?傳參,而?params?傳參又可分為在?url?中顯示參數(shù)和不顯示參數(shù)兩種方式,這就是vue路由傳參的三種方式,感興趣的朋友跟隨小編一起看看吧2023-07-07VUE PC端可拖動(dòng)懸浮按鈕的實(shí)現(xiàn)代碼
這篇文章主要介紹了VUE PC端可拖動(dòng)懸浮按鈕的實(shí)現(xiàn)代碼,通過實(shí)例代碼介紹了父頁面引用的方法,本文結(jié)合實(shí)例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下2024-02-02vue如何調(diào)用攝像頭實(shí)現(xiàn)拍照上傳圖片、本地上傳圖片
這篇文章主要給大家介紹了關(guān)于vue如何調(diào)用攝像頭實(shí)現(xiàn)拍照上傳圖片、本地上傳圖片的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2023-07-07