mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
Field 增加blur事件 && Field 支持尾部icon (#53)
This commit is contained in:
parent
41557ba0f1
commit
ac6abf67b7
@ -14,6 +14,15 @@ export default {
|
|||||||
return {
|
return {
|
||||||
username: 'zhangmin'
|
username: 'zhangmin'
|
||||||
};
|
};
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
onIconClick() {
|
||||||
|
this.username = '';
|
||||||
|
},
|
||||||
|
|
||||||
|
onFieldBlur() {
|
||||||
|
console.log('blured');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
@ -62,7 +71,15 @@ export default {
|
|||||||
:::demo 基础用法
|
:::demo 基础用法
|
||||||
```html
|
```html
|
||||||
<van-cell-group>
|
<van-cell-group>
|
||||||
<van-field type="text" label="用户名:" placeholder="请输入用户名" v-model="username" required></van-field>
|
<van-field
|
||||||
|
type="text"
|
||||||
|
label="用户名:"
|
||||||
|
placeholder="请输入用户名"
|
||||||
|
v-model="username"
|
||||||
|
icon="clear"
|
||||||
|
:on-icon-click="onIconClick"
|
||||||
|
@blur="onFieldBlur"
|
||||||
|
required></van-field>
|
||||||
<van-field type="password" label="密码:" placeholder="请输入密码" required></van-field>
|
<van-field type="password" label="密码:" placeholder="请输入密码" required></van-field>
|
||||||
<van-field type="textarea" label="个人介绍:" placeholder="请输入个人介绍" required></van-field>
|
<van-field type="textarea" label="个人介绍:" placeholder="请输入个人介绍" required></van-field>
|
||||||
</van-cell-group>
|
</van-cell-group>
|
||||||
@ -145,4 +162,6 @@ export default {
|
|||||||
| rows | textarea rows | `string`, `number` | | |
|
| rows | textarea rows | `string`, `number` | | |
|
||||||
| cols | textarea cols | `string`, `number` | | |
|
| cols | textarea cols | `string`, `number` | | |
|
||||||
| autosize | 自动调整高度(仅支持textarea) | `boolean` | `false` | `true`, `false` |
|
| autosize | 自动调整高度(仅支持textarea) | `boolean` | `false` | `true`, `false` |
|
||||||
|
| icon | 输入框尾部图标 | `string` | | icon中支持的类型 |
|
||||||
|
| onIconClick | 点击图标的回调函数 | `function` | | |
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
class="van-field__control"
|
class="van-field__control"
|
||||||
v-model="currentValue"
|
v-model="currentValue"
|
||||||
@focus="handleInputFocus"
|
@focus="handleInputFocus"
|
||||||
|
@blur="handleInputBlur"
|
||||||
:placeholder="placeholder"
|
:placeholder="placeholder"
|
||||||
:maxlength="maxlength"
|
:maxlength="maxlength"
|
||||||
:disabled="disabled"
|
:disabled="disabled"
|
||||||
@ -30,23 +31,27 @@
|
|||||||
:value="currentValue"
|
:value="currentValue"
|
||||||
@input="handleInput"
|
@input="handleInput"
|
||||||
@focus="handleInputFocus"
|
@focus="handleInputFocus"
|
||||||
|
@blur="handleInputBlur"
|
||||||
:type="type"
|
:type="type"
|
||||||
:placeholder="placeholder"
|
:placeholder="placeholder"
|
||||||
:maxlength="maxlength"
|
:maxlength="maxlength"
|
||||||
:disabled="disabled"
|
:disabled="disabled"
|
||||||
:readonly="readonly">
|
:readonly="readonly">
|
||||||
|
<van-icon v-if="icon" :name="icon" class="van-field__icon" @click="onIconClick"></van-icon>
|
||||||
</van-cell>
|
</van-cell>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
const VALID_TYPES = ['text', 'number', 'email', 'url', 'tel', 'date', 'time', 'datetime', 'password', 'textarea'];
|
const VALID_TYPES = ['text', 'number', 'email', 'url', 'tel', 'date', 'time', 'datetime', 'password', 'textarea'];
|
||||||
import vanCell from 'packages/cell';
|
import vanCell from 'packages/cell';
|
||||||
|
import vanIcon from 'packages/icon';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'van-field',
|
name: 'van-field',
|
||||||
|
|
||||||
components: {
|
components: {
|
||||||
vanCell
|
vanCell,
|
||||||
|
vanIcon
|
||||||
},
|
},
|
||||||
|
|
||||||
props: {
|
props: {
|
||||||
@ -71,6 +76,11 @@ export default {
|
|||||||
autosize: {
|
autosize: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false
|
default: false
|
||||||
|
},
|
||||||
|
icon: String,
|
||||||
|
onIconClick: {
|
||||||
|
type: Function,
|
||||||
|
default: () => {}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -107,6 +117,10 @@ export default {
|
|||||||
|
|
||||||
handleInputFocus() {
|
handleInputFocus() {
|
||||||
this.$emit('focus');
|
this.$emit('focus');
|
||||||
|
},
|
||||||
|
|
||||||
|
handleInputBlur() {
|
||||||
|
this.$emit('blur');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
@import './common/var.css';
|
@import './common/var.css';
|
||||||
@import './mixins/border_retina.css';
|
@import './mixins/border_retina.css';
|
||||||
@import './cell.css';
|
@import './cell.css';
|
||||||
|
@import './icon.css';
|
||||||
|
|
||||||
@component-namespace van {
|
@component-namespace van {
|
||||||
@b field {
|
@b field {
|
||||||
@ -85,5 +86,13 @@
|
|||||||
resize: none;
|
resize: none;
|
||||||
outline: 0;
|
outline: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@e icon {
|
||||||
|
position: absolute;
|
||||||
|
right: 0;
|
||||||
|
top: 50%;
|
||||||
|
transform: translate3d(0, -50%, 0);
|
||||||
|
padding: 10px;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user