commit
8ac054ee05
|
@ -2,16 +2,27 @@ import { tag, render, WeElement } from '../../src/omi'
|
|||
|
||||
@tag('hello-element')
|
||||
class HelloElement extends WeElement {
|
||||
render() {
|
||||
return [<div>Hello</div>, <div>Element</div>]
|
||||
render(props) {
|
||||
const { count } = props
|
||||
return [<div>Hello</div>, <div>Element</div>,<div>{count}</div>]
|
||||
}
|
||||
}
|
||||
|
||||
@tag('my-app')
|
||||
class MyApp extends WeElement {
|
||||
data = {
|
||||
count: 1
|
||||
}
|
||||
render() {
|
||||
return [<hello-element />, <hello-element />, <div>abc</div>]
|
||||
}
|
||||
|
||||
installed() {
|
||||
setInterval(() => {
|
||||
this.data.count++
|
||||
this.update()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
render(<my-app />, 'body')
|
||||
|
|
|
@ -28,7 +28,18 @@ export default class WeElement extends HTMLElement {
|
|||
}
|
||||
|
||||
this.install()
|
||||
const shadowRoot = this.attachShadow({ mode: 'open' })
|
||||
var shadowRoot
|
||||
if (!this.shadowRoot) {
|
||||
shadowRoot = this.attachShadow({
|
||||
mode: 'open'
|
||||
})
|
||||
} else {
|
||||
shadowRoot = this.shadowRoot
|
||||
var fc
|
||||
while (fc = shadowRoot.firstChild) {
|
||||
shadowRoot.removeChild(fc)
|
||||
}
|
||||
}
|
||||
|
||||
this.css && shadowRoot.appendChild(cssToDom(this.css()))
|
||||
this.beforeRender()
|
||||
|
|
Loading…
Reference in New Issue