update site

This commit is contained in:
dntzhang 2019-05-06 17:55:05 +08:00
parent bf37568324
commit 5623402aa8
2 changed files with 26 additions and 4 deletions

View File

@ -39,7 +39,7 @@ Using element:
<my-element myObj={{ name: 'world' }}></my-element>
```
You can set the default value by the static default Props property:
You can set the default value by the `static defaultProps` propertyuse `static propTypes` to set the type:
```jsx
define('my-element', class extends WeElement {
@ -48,10 +48,21 @@ define('my-element', class extends WeElement {
myAge: 18
}
static propTypes = {
name: String,
myAge: Number
}
render(props) {
return (
<h1>Hello, {props.name}! Age {props.myAge}</h1>
)
}
})
```
```
Special attention should be paid to adding `static propTypes` if your custom elements want to be used directly in other frameworks or without frameworks. For example, it can be used directly in the body:
<body>
<my-element name="dntzhang" my-age="20"></my-element>
</body>

View File

@ -39,13 +39,18 @@ define('my-element', class extends WeElement {
<my-element myObj={{ name: 'world' }}></my-element>
```
你可以通过静态属性 `static defaultProps` 来设置默认值:
你可以通过静态属性 `static defaultProps` 来设置默认值,使用 `static propTypes` 来设置类型:
```jsx
define('my-element', class extends WeElement {
static defaultProps = {
name: 'Omi',
myAge: 18
}
static propTypes = {
name: String,
myAge: Number
}
render(props) {
@ -54,4 +59,10 @@ define('my-element', class extends WeElement {
)
}
})
```
```
需要特别注意,如果你的自定义元素想要直接在其他框架或者无框架的情况下原生使用,请一定要加上 `static propTypes` 才能生效。比如,这样就可以直接在 body 中使用:
<body>
<my-element name="dntzhang" my-age="20"></my-element>
</body>