You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
657 B

2 years ago
  1. import React from 'react'
  2. /*
  3. 第一种defaultProps
  4. 第二种 static 类静态属性定义 (推荐)
  5. */
  6. class Test extends React.Component {
  7. // 第二种: static 类静态属性定义
  8. static defaultProps = {
  9. pageSize: 10
  10. }
  11. render () {
  12. return (
  13. <div>
  14. {this.props.pageSize}
  15. </div>
  16. )
  17. }
  18. }
  19. // 第一种:defaultProps
  20. /* Test.defaultProps = {
  21. pageSize: 10
  22. } */
  23. class App extends React.Component {
  24. render () {
  25. return (
  26. <div>
  27. <Test pageSize={20}/>
  28. </div>
  29. )
  30. }
  31. }
  32. export default App