簡體   English   中英

我正在嘗試在 React 中創建一個盒子,但它不起作用

[英]I am trying to create a box in React, and it is not working

這是我的代碼:

   class Landing extends Component {
  state = {
    box: " width: 300px , height: 100px, border: 1px solid blue; ",
  };


  render() {
    return <div className={this.state.box}>Hello</div>;
  }
}

這個想法是“你好”應該在一個盒子里。

相反,我得到的是一個沒有框的 web 頁面,只有一個你好。

請幫忙。

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM