[英]I am trying to create a box in React, and it is not working
Here is my code:这是我的代码:
class Landing extends Component {
state = {
box: " width: 300px , height: 100px, border: 1px solid blue; ",
};
render() {
return <div className={this.state.box}>Hello</div>;
}
}
The idea is that "Hello" should be inside a box.这个想法是“你好”应该在一个盒子里。
Instead, what I am getting is a web page with no box, just a hello.相反,我得到的是一个没有框的 web 页面,只有一个你好。
Please help.请帮忙。
Change className
to style
and turn box
in to a real object.将
className
更改为style
,并将box
in 变为真实的 object。
class Landing extends Component {
state = {
box: {width: '300px', height: '100px', border: '1px solid blue'},
};
render() {
return <div style={this.state.box}>Hello</div>;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.