Vue-cli3生成的Vue项目加载Mxgraph方法示例
更新时间:2020年05月31日 10:18:47 作者:懒牛不爱梳毛
这篇文章主要介绍了Vue-cli3生成的Vue项目加载Mxgraph方法示例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
使用Vue-cli3生成Vue项目,并等待项目创建成功。
vue create [项目名]
安装mxgraph。
cnpm install mxgraph --save
安装exports-loader。
cnpm install exports-loader --save
安装script-loader。
cnpm install script-loader --save
在项目根目录新建vue.config.js文件。
将以下内容复制到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,替换为以下内容。
<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>
运行项目,查看效果。此Demo的源码可以查看
到此这篇关于Vue-cli3生成的Vue项目加载Mxgraph方法示例的文章就介绍到这了,更多相关Vue项目加载Mxgraph内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
您可能感兴趣的文章:
相关文章
vue项目中在外部js文件中直接调用vue实例的方法比如说this
这篇文章主要介绍了vue项目中在外部js文件中直接调用vue实例的方法比如说this,需要的朋友可以参考下2019-04-04
lottie实现vue自定义loading指令及常用指令封装详解
这篇文章主要为大家介绍了lottie实现vue自定义loading指令及常用指令封装,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪2022-09-09
Vue CLI3创建项目部署到Tomcat 使用ngrok映射到外网
这篇文章主要介绍了Vue CLI3创建项目部署到Tomcat 使用ngrok映射到外网,本文通过实例代码给大家介绍的非常详细,具有一定的参考借鉴价值,需要的朋友可以参考下2019-05-05


最新评论