update site

This commit is contained in:
dntzhang 2019-03-15 11:35:51 +08:00
parent 2c4fb978bf
commit cabd716319
1 changed files with 57 additions and 0 deletions

57
site/src/docs/en/props.md Normal file
View File

@ -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>
)
}
})
```