Vue3 前端 引入 markmap 思维导图,通过markdown解析成思维导图
安装
// npm install markmap-lib // npm install markmap-view // npm install markmap-common
完整代码
import { ref, onMounted, onUpdated } from 'vue' import { Transformer } from 'markmap-lib' import { Markmap } from 'markmap-view' import * as htmlToImage from 'html-to-image' import { saveAs } from 'file-saver' const transformer = new Transformer() const initValue = ` # 思维导图 1. 标题1 - 子标题1 - 子标题2 3. 标题2 4. 标题3 - beautiful - useful - easy - interactive ` const mm = ref() const svgRef = ref() const update = () => { const { root } = transformer.transform(initValue) mm.value.setData(root) mm.value.fit() } const zoomIn = () => mm.value.rescale(1.25) const zoomOut = () => mm.value.rescale(0.8) const fitToScreen = () => mm.value.fit() const onSave = async () => { const dataUrl = await htmlToImage.toPng(svgRef.value) saveAs(dataUrl, 'markmap.png') } onMounted(() => { // 初始化markmap思维导图 mm.value = Markmap.create(svgRef.value) // 更新思维导图渲染 update() }) onUpdated(update) 放大 缩小 适应屏幕 下载 .mind { width: 100%; height: 100%; display: flex; flex-direction: column; .svg-container { flex: 1; svg { width: 100%; height: 100%; } } .controls { display: flex; justify-content: center; align-items: center; height: 50px; } } .controls { margin-top: 10px; }
文章版权声明:除非注明,否则均为主机测评原创文章,转载或复制请以超链接形式并注明出处。