create-react-app中的CytoscapeJS不触发console.log

时间:2019-11-15 14:08:13

标签: reactjs create-react-app cytoscape.js

我将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

0 个答案:

没有答案