思维导图在开发中也是比较常见的需求了,尤其是后台管理系统之类的项目中,如果你还不会用,那么这篇文章可能对你有帮助

安装jsmind

npm install jsmind --save

vue2.x

<script>
import jsMind from 'jsmind'
import 'jsmind/draggable-node'
import 'jsmind/style/jsmind.css'

export default {
    data() {
        return {
            jsmind_options : {
                editable: true,
                theme: 'primary',
            },
            jsmind_data : {
                meta: {
			        name: 'demo',
			        author: 'test@example.com',
			        version: '0.2',
			    },
			    format: 'node_array',
			    data: [
			        { id: 'root', isroot: true, topic: 'jsMind' },
			        { id: 'sub1', parentid: 'root', topic: 'sub1' },
			        { id: 'sub11', parentid: 'sub1', topic: 'sub11' },
			        { id: 'sub12', parentid: 'sub1', topic: 'sub12' },
			        { id: 'sub13', parentid: 'sub1', topic: 'sub13' },
			
			        { id: 'sub2', parentid: 'root', topic: 'sub2' },
			        { id: 'sub21', parentid: 'sub2', topic: 'sub21' },
			        { id: 'sub22', parentid: 'sub2', topic: 'sub22' },
			
			        { id: 'sub3', parentid: 'root', topic: 'sub3' },
			    ],
            }
        }
    },
    mounted() {
        let options = Object.assign(this.jsmind_options, {
            container: this.$refs.jsmind_container
        });
        let jm = new jsMind(options);
        jm.show(this.jsmind_data);
    }
}
</script>

<style scoped>
    .jsmind-container {
        width: 1024px;
        height: 700px;
        border: solid 1px #ccc;
    }
</style>

<template>
    <div ref="jsmind_container" class="jsmind-container"></div>
</template>

vue3

<template>
  <div>
    <div ref="jsmindContainer" class="jsmind-container"></div>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue';
import JSMind from 'jsmind';
import "jsmind/draggable-node";
import "jsmind/style/jsmind.css";
const jsmindContainer = ref(null);//获取jsmindContainer的ref
let jsmind_options = ref({
  editable: true,
  theme: "primary",
});
let jsmind_data = ref({
  	meta: {
        name: 'demo',
        author: 'test@example.com',
        version: '0.2',
    },
    format: 'node_array',
    data: [
        { id: 'root', isroot: true, topic: 'jsMind' },
        { id: 'sub1', parentid: 'root', topic: 'sub1' },
        { id: 'sub11', parentid: 'sub1', topic: 'sub11' },
        { id: 'sub12', parentid: 'sub1', topic: 'sub12' },
        { id: 'sub13', parentid: 'sub1', topic: 'sub13' },

        { id: 'sub2', parentid: 'root', topic: 'sub2' },
        { id: 'sub21', parentid: 'sub2', topic: 'sub21' },
        { id: 'sub22', parentid: 'sub2', topic: 'sub22' },

        { id: 'sub3', parentid: 'root', topic: 'sub3' },
    ],
});
onMounted(() => {
  createMind();
});

const createMind = () => {
	let options = Object.assign(jsmind_options.value, {
	  container: jsmindContainer ,
	});
	let jm = new jsMind(options);
	jm.show(jsmind_data.value);
}
</script>

<style>
.jsmind-container {
  /* 给脑图容器添加一些样式 */
  border: 1px solid #ccc;
}
</style>

怎么样,是不是很简单

GitHub 加速计划 / vu / vue
207.54 K
33.66 K
下载
vuejs/vue: 是一个用于构建用户界面的 JavaScript 框架,具有简洁的语法和丰富的组件库,可以用于开发单页面应用程序和多页面应用程序。
最近提交(Master分支:2 个月前 )
73486cb5 * chore: fix link broken Signed-off-by: snoppy <michaleli@foxmail.com> * Update packages/template-compiler/README.md [skip ci] --------- Signed-off-by: snoppy <michaleli@foxmail.com> Co-authored-by: Eduardo San Martin Morote <posva@users.noreply.github.com> 4 个月前
e428d891 Updated Browser Compatibility reference. The previous currently returns HTTP 404. 5 个月前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐