【发布时间】:2020-02-21 03:36:00
【问题描述】:
我收到此错误...
5440 | this.bindModules();
5441 |
> 5442 | if (this.element.tagName === "TABLE") {
| ^ 5443 | if (this.modExists("htmlTableImport", true)) {
5444 | this.modules.htmlTableImport.parseTable();
5445 | }
当我尝试使用Tabulator library in a React component。
import React, { useState, useEffect } from "react";
import Tabulator from "tabulator-tables";
import "tabulator-tables/dist/css/tabulator.min.css";
function Journal(props) {
let refTable = React.createRef();
const [journalItems, setJournalItems] = useState([]);
useEffect(() => {
new Tabulator(refTable, {
data: journalItems,
reactiveData: true,
columns: ["a", "b", "c"],
});
}, []);
return (
<div>
<div className="foo" ref={refTable}></div>
</div >
)
}
export default Journal;
library example 使用类组件方法,而我想使用函数式方法。
我做错了什么?
【问题讨论】:
-
console.log(this);可能是很好的第一步。可能是this的简单案例,并不意味着您认为this应该是什么。其次,(如果this案例检查出来)是看看this.element是什么。是undefined吗?我敢打赌... -
this不是没用在功能组件里吗?
标签: javascript reactjs tabulator