【发布时间】:2021-06-12 10:08:24
【问题描述】:
我在 React 中玩耍,我试图让一个方法返回一个值,然后我将使用它在 render() 方法中显示,但是当我尝试什么都不显示时。
import React, { Component } from "react";
class Test extends Component {
constructor(props) {
super(props);
this.DisplayTest = this.DisplayTest.bind(this);
}
DisplayTest() {
return <h1>Test</h1>;
}
render() {
return <div>{this.DisplayTest}</div>;
}
}
export default Test;
【问题讨论】:
-
您需要将方法调用为
{this.DisplayTest()}
标签: javascript html node.js reactjs