首页 > 解决方案 > create-react-app 中的 CytoscapeJS 未触发 console.log

问题描述

Cytoscape.jscreate-react-app. 终端正在运行应用程序,但没有输出console.log. 尤其是在handleClick方法上。

import React, { Component } from 'react'
import Cs from 'cytoscape'
const { cyConfig, cyStyle } = require('./config/config')

class Graph extends Component {
  componentDidMount () {
    cyConfig.container = document.getElementById('cy')
    this.cy = Cs(cyConfig)
  }

  handleClick () {
    this.cy.on('tap', 'node', (e) => {
      const node = e.target
      console.log(node.id())
    })
  }

  render() {
    return (
      <div
        style={cyStyle}
        id='cy'
        onClick={ (e) => this.handleClick(e) }
      />
    )
  }

}

export default Graph

标签: reactjscreate-react-appcytoscape.js

解决方案


推荐阅读