vue2.0实现JSMIND点击节点获取当前节点数据

181 阅读1分钟

核心代码逻辑如下

 <div id="jsmind_container" ref="jsmindContainer">
  </div>
  methods: {
    handleClick(event) {
      const target = event.target;
      const nodeId = target.getAttribute('nodeid');
      if (nodeId) {
        const node = this.jm.get_node(nodeId);
        this.handleNodeClick(node);
      }
    },
    handleNodeClick(node) {
      console.log(node); // 在这里处理节点点击事件,例如显示节点信息、跳转等 }, }, };
    }
  },
  mounted() {
    this.jm = new jsMind(this.options);
    this.jm.show(this.mind);
    this.jm.resize();
    this.$refs.jsmindContainer.addEventListener('click', this.handleClick);
  }

点击节点 控制台就能打印出来对应的数据 如图所示

image.png