This commit is contained in:
dntzhang 2019-05-03 16:34:50 +08:00
parent d1d0c7aff4
commit 065c136b01
3 changed files with 13 additions and 6 deletions

View File

@ -5,6 +5,10 @@ import '../my-element'
import './index.css'
define('my-counter', class extends WeElement {
static defaultProps = {
aa: 'aaaaa'
}
data = {
count: 1
}
@ -28,6 +32,7 @@ define('my-counter', class extends WeElement {
<text>{this.data.count}</text>
<button onClick={this.add}>+</button>
<my-element msg='omi'></my-element>
<view>{this.props.aa}</view>
</view>
)
}

View File

@ -28,11 +28,11 @@ export function define(name, ctor) {
}
}
})
ins.props = this.properties
//ins.props = this.properties
}
config.properties = ctor.properties
Object.keys(ctor.properties).forEach(key => {
ctor.properties[key].observer = function (newVal, oldVal, changedPath) {
ins.props[key] = newVal
@ -41,7 +41,7 @@ export function define(name, ctor) {
})
config.attached = function () {
ins.props = this.properties
//ins.props = this.properties
ins.install.call(ins)
ins.update()
}

View File

@ -4,7 +4,9 @@ import { define } from './define'
import { updateData } from './update-data'
class Component {
constructor() { }
constructor() {
this.props = Object.assign({}, this.constructor.defaultProps)
}
data = {}
@ -12,9 +14,9 @@ class Component {
this.beforeUpdate && this.beforeUpdate()
this.beforeRender && this.beforeRender()
try {
this._createData()
Object.assign(this._createData(), this.props)
} catch (e) {
console.log(e)
}