-
Notifications
You must be signed in to change notification settings - Fork 10
/
Input.vue
104 lines (102 loc) · 2.21 KB
/
Input.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
94
95
96
97
98
99
100
101
102
103
104
<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 && val"></i>
</div>
</template>
<script>
import { ref } from 'vue';
export default {
props: {
type: {
type: String,
default: () => {
return 'text';
}
},
max: {
type: String || Number,
default: () => {
return '';
}
},
placeholder: {
type: String,
default: () => {
return '';
}
},
clear: {
type: String,
default: () => {
return undefined;
}
}
},
setup (props, {emit}) {
const val = ref('');
// 失去焦点
const blur =()=> {
event.stopPropagation();
emit('blur', event.target.value);
}
// change事件
const change =()=> {
event.stopPropagation();
emit('change', event.target.value);
}
// input事件
const input =()=> {
event.stopPropagation();
emit('input', event.target.value);
}
// focus事件
const focus =()=> {
event.stopPropagation();
emit('focus', event.target.value);
}
// 清理输入内容
const clearValue =()=> {
val.value = '';
}
// 暴露给模板
return {
val,
blur,
change,
input,
focus,
clearValue
};
}
}
</script>
<style lang='less' rel='stylesheet/less' scoped>
.wt-TextField {
height: 1.5rem;
position: relative;
border: 1px solid #eee;
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>