我是 jointjs 的新手,很难在我的 React 项目中导入 jointjs。我得到的错误是 类型错误:无法读取未定义的属性“dia”。我在我的项目中使用这个版本: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;
最佳答案
根据文档,不再有默认导入。
你需要这样做
import * as joint from 'jointjs'
或者您可以通过 -
导入dia
本身
import { dia } from 'jointjs/src/core.mjs';
关于reactjs - 无法读取未定义的属性 'dia',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58927307/