mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
[Improvement] Field: support native events (#421)
This commit is contained in:
parent
51ce4d0843
commit
e2ec1ecd13
@ -90,6 +90,7 @@ Filed support all native properties of input tag,such as `maxlength`、`placeh
|
||||
| icon | Right side Icon name | `String` | - | - |
|
||||
|
||||
### Event
|
||||
Filed support all native events of input tag,such as `keypress`、`keyup`
|
||||
|
||||
| Event | Description | Parameters |
|
||||
|-----------|-----------|-----------|
|
||||
|
@ -92,6 +92,7 @@ Filed 默认支持 Input 标签所有的原生属性,比如 `maxlength`、`pla
|
||||
| icon | 输入框尾部图标 | `String` | - | Icon 组件支持的类型 |
|
||||
|
||||
### Event
|
||||
Filed 默认支持 Input 标签所有的原生事件,比如 `keypress`、`keyup` 等
|
||||
|
||||
| 事件名称 | 说明 | 回调参数 |
|
||||
|-----------|-----------|-----------|
|
||||
|
@ -16,23 +16,18 @@
|
||||
<textarea
|
||||
v-if="type === 'textarea'"
|
||||
v-bind="$attrs"
|
||||
v-on="listeners"
|
||||
ref="textarea"
|
||||
class="van-field__control"
|
||||
:value="value"
|
||||
@input="onInput"
|
||||
@focus="$emit('focus')"
|
||||
@blur="$emit('blur')"
|
||||
/>
|
||||
<input
|
||||
v-else
|
||||
v-bind="$attrs"
|
||||
v-on="listeners"
|
||||
class="van-field__control"
|
||||
:type="type"
|
||||
:value="value"
|
||||
@keypress="onKeypress"
|
||||
@input="onInput"
|
||||
@focus="$emit('focus')"
|
||||
@blur="$emit('blur')"
|
||||
/>
|
||||
<div
|
||||
v-if="hasIcon"
|
||||
@ -98,6 +93,14 @@ export default create({
|
||||
computed: {
|
||||
hasIcon() {
|
||||
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();
|
||||
}
|
||||
}
|
||||
this.$emit('keypress', event);
|
||||
},
|
||||
|
||||
adjustSize() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user