omip - fix event

This commit is contained in:
dntzhang 2019-02-26 13:14:18 +08:00
parent ff8f1c9ff6
commit 5e2a96afbb
3 changed files with 13 additions and 4 deletions

View File

@ -2,7 +2,6 @@
import { WeElement, define } from 'omi'
import '../my-element'
//兼容 omi 下划线?
import './index.css'
define('my-counter', class extends WeElement {
@ -16,11 +15,13 @@ define('my-counter', class extends WeElement {
sub = () => {
this.data.count--
this.fire('change', this.data.count)
this.update()
}
add = () => {
this.data.count++
this.fire('change', this.data.count)
this.update()
}

View File

@ -10,6 +10,10 @@ class Component {
}
install() { }
fire(type, data) {
this._weappRef.triggerEvent(type, data)
}
}
const WeElement = Component

View File

@ -1,7 +1,7 @@
import util from '../../utils/util'
import { WeElement, define } from 'omi'
import '../../components/my-counter'
//兼容 omi 下划线?
import './index.css'
define('page-logs', class extends WeElement {
@ -15,12 +15,16 @@ define('page-logs', class extends WeElement {
})
this.update()
}
counterChange = (evt)=> {
console.log(evt.detail)
}
render() {
return (
<view>
<my-counter></my-counter>
<my-counter onChange={this.counterChange}></my-counter>
<view class="container log-list">
{this.data.logs.map((log, index) => (
<text class="log-item">{index + 1}. {log}</text>