-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathTextField.vue
93 lines (93 loc) · 1.97 KB
/
TextField.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<template>
<div class='wt-TextField'>
<input :type="type" :maxlength="max" v-model="val" :placeholder="placeholder" @blur="blur" @change="change" @input="input" @focus="focus"/>
<i class="icon-close-fill" @click="clearValue" v-if="clear != undefined"></i>
</div>
</template>
<script>
export default {
name: 'wt-TextField',
props: {
type: {
type: String,
default: () => {
return 'text';
}
},
max: {
type: String | Number,
default: () => {
return '';
}
},
placeholder: {
type: String,
default: () => {
return '';
}
},
clear: {
type: String,
default: () => {
return undefined;
}
}
},
data () {
return {
val: '' // 输入框的值
};
},
methods: {
// 失去焦点
blur () {
this.$emit('blur', event.target.value);
},
// change事件
change () {
this.$emit('change', event.target.value);
},
// input事件
input () {
this.$emit('input', event.target.value);
},
// focus事件
focus () {
this.$emit('focus', event.target.value);
},
// 清理输入内容
clearValue () {
this.val = '';
}
}
};
</script>
<style lang='less' rel='stylesheet/less' scoped>
.wt-TextField {
height: 1.5rem;
position: relative;
padding: 0.5rem;
display: flex;
i {
background: #fff;
width: 1.5rem;
line-height: 1.5rem;
color: #cacaca;
text-align: center;
}
input {
outline: none;
-webkit-appearance: none;
background: #fff;
border: 0;
height: 1.5rem;
width: 100%;
display: block;
padding-left: 0.2rem;
box-sizing: border-box;
&::-webkit-search-cancel-button{
display: none;
}
}
}
</style>