Merge pull request #161 from 1921622004/master

修复render返回数组的问题
This commit is contained in:
当耐特 2018-11-05 22:01:26 +08:00 committed by GitHub
commit 8ac054ee05
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 3 deletions

View File

@ -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')

View File

@ -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()