无法读取未定义的属性“dia”

Moj*_*ojo 2 jointjs reactjs

我是jointjs的新手,很难在我的React项目中导入jointjs。我得到的错误是 TypeError: Cannot read property 'dia' of undefined。我在我的项目jointjs:3.0.4、lodash:4.17.14和jquery:3.4.1中使用这个版本;

import React from 'react';
import $ from "jquery";
import  _ from "lodash";
import './App.css';
import joint from "jointjs";


class App extends React.Component{  

  constructor(){
    super()

  }

  componentDidMount(){
    this.InitializeGraph();
  }

InitializeGraph(){

  var graph = new joint.dia.Graph;
  new joint.dia.Paper({ el: $('#paper-html-elements'), width: 650, height: 400, gridSize: 1, model: 
  graph });

 }


  render(){
    return(
    <div>
   <div id='paper-html-elements'> </div>
    </div>
    )
  }
}

export default App;
Run Code Online (Sandbox Code Playgroud)

Ati*_*ngh 6

根据文档,不再有默认导入。

你需要这样做

import * as joint from 'jointjs'
Run Code Online (Sandbox Code Playgroud)

或者您可以dia通过以下方式导入自己 -

import { dia } from 'jointjs/src/core.mjs';
Run Code Online (Sandbox Code Playgroud)