update site
This commit is contained in:
parent
2c4fb978bf
commit
cabd716319
|
@ -0,0 +1,57 @@
|
|||
|
||||
## Props
|
||||
|
||||
Transfer data to sub elements through props, such as:
|
||||
|
||||
```jsx
|
||||
import { WeElement, define, render } from 'omi'
|
||||
|
||||
define('my-element', class extends WeElement {
|
||||
render(props) {
|
||||
return (
|
||||
<h1>Hello, {props.name}!</h1>
|
||||
)
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
Using element:
|
||||
|
||||
```jsx
|
||||
<my-element name="world"></my-first-element>
|
||||
```
|
||||
|
||||
You can also pass any type of data to props:
|
||||
|
||||
```jsx
|
||||
define('my-element', class extends WeElement {
|
||||
render(props) {
|
||||
return (
|
||||
<h1>Hello, {props.myObj.name}!</h1>
|
||||
)
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
Using element:
|
||||
|
||||
```jsx
|
||||
<my-first-element myObj={{ name: 'world' }}></my-first-element>
|
||||
```
|
||||
|
||||
You can set the default value by the static default Props property:
|
||||
|
||||
```jsx
|
||||
define('my-first-element', class extends WeElement {
|
||||
static defaultProps = {
|
||||
name: 'Omi',
|
||||
myAge: 18
|
||||
}
|
||||
|
||||
render(props) {
|
||||
return (
|
||||
<h1>Hello, {props.name}! Age {props.myAge}</h1>
|
||||
)
|
||||
}
|
||||
})
|
||||
```
|
Loading…
Reference in New Issue