omi - add extend demo with select

This commit is contained in:
dntzhang 2019-08-04 08:06:06 +08:00
parent eed04e8591
commit 703f7f03f6
4 changed files with 1969 additions and 0 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,10 @@
<html>
<head></head>
<body>
<script src="b.js"></script>
</body>
</html>

View File

@ -0,0 +1,29 @@
import { define, render, WeElement, extend, set, get } from '../../src/omi'
extend('model-select', (el, path, scope) => {
el.value = get(scope, path)
el.addEventListener('change', (evt) => {
set(scope, path, el.value)
scope.update()
})
})
define('my-component', class extends WeElement {
selected = 'b'
render() {
return (
<div>
<select o-model-select='selected'>
<option value="a">Item A</option>
<option value="b">Item B</option>
</select>
<div>{this.selected}</div>
</div>
)
}
})
render(<my-component />, 'body')