[Improvement] Field: support native events (#421)

This commit is contained in:
neverland 2017-12-12 20:54:32 +08:00 committed by GitHub
parent 51ce4d0843
commit e2ec1ecd13
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 7 deletions

View File

@ -90,6 +90,7 @@ Filed support all native properties of input tagsuch as `maxlength`、`placeh
| icon | Right side Icon name | `String` | - | - | | icon | Right side Icon name | `String` | - | - |
### Event ### Event
Filed support all native events of input tagsuch as `keypress``keyup`
| Event | Description | Parameters | | Event | Description | Parameters |
|-----------|-----------|-----------| |-----------|-----------|-----------|

View File

@ -92,6 +92,7 @@ Filed 默认支持 Input 标签所有的原生属性,比如 `maxlength`、`pla
| icon | 输入框尾部图标 | `String` | - | Icon 组件支持的类型 | | icon | 输入框尾部图标 | `String` | - | Icon 组件支持的类型 |
### Event ### Event
Filed 默认支持 Input 标签所有的原生事件,比如 `keypress``keyup`
| 事件名称 | 说明 | 回调参数 | | 事件名称 | 说明 | 回调参数 |
|-----------|-----------|-----------| |-----------|-----------|-----------|

View File

@ -16,23 +16,18 @@
<textarea <textarea
v-if="type === 'textarea'" v-if="type === 'textarea'"
v-bind="$attrs" v-bind="$attrs"
v-on="listeners"
ref="textarea" ref="textarea"
class="van-field__control" class="van-field__control"
:value="value" :value="value"
@input="onInput"
@focus="$emit('focus')"
@blur="$emit('blur')"
/> />
<input <input
v-else v-else
v-bind="$attrs" v-bind="$attrs"
v-on="listeners"
class="van-field__control" class="van-field__control"
:type="type" :type="type"
:value="value" :value="value"
@keypress="onKeypress"
@input="onInput"
@focus="$emit('focus')"
@blur="$emit('blur')"
/> />
<div <div
v-if="hasIcon" v-if="hasIcon"
@ -98,6 +93,14 @@ export default create({
computed: { computed: {
hasIcon() { hasIcon() {
return this.$slots.icon || this.icon; return this.$slots.icon || this.icon;
},
listeners() {
return {
...this.$listeners,
input: this.onInput,
keypress: this.onKeypress
};
} }
}, },
@ -120,6 +123,7 @@ export default create({
event.preventDefault(); event.preventDefault();
} }
} }
this.$emit('keypress', event);
}, },
adjustSize() { adjustSize() {