add omi-30-seconds

This commit is contained in:
dntzhang 2018-11-19 12:47:40 +08:00
parent f686526dff
commit 8097769154
1 changed files with 59 additions and 0 deletions

View File

@ -0,0 +1,59 @@
## Omi 30 Seconds
Curated collection of useful Omi snippets that you can understand in 30 seconds or less.
## Overview of the Readme
- Share css between parent and child nodes[#share-css-between-parent-and-child-nodes]
## Share css between parent and child nodes
```js
import { define, WeElement, render, getHost } from 'omi'
define('my-ele', class extends WeElement {
install() {
this.css = getHost().css
}
render() {
return props.children[0]
}
})
define('my-parent-ele', class extends WeElement {
css() {
return `div { color: red; }`
}
render() {
return (
<div>
<my-ele>
<div>content</div>
</my-ele>
</div>
)
}
})
render(<my-parent-ele />, 'body')
```
Share css by `getHost` method. You can also recombine with the parent node's css and custom css.
```js
define('my-ele', class extends WeElement {
css() {
return getHost().css() + `
font-size: 34px;
`
}
render() {
return props.children[0]
}
})
```