inputx.vue
1.65 KB
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="input-wrapper">
<span class="input-prefix">
<slot name="prefix"></slot>
</span>
<input type="text" :maxlength="maxlength" :readonly="readonly" class="input" :class="classes" :value="value" @input="onInput">
<span class="input-suffix">
<slot name="suffix"></slot>
</span>
</div>
</template>
<script>
export default {
data() {
return {
classes: {}
};
},
props: {
value: [String, Number],
maxlength: Number,
readonly: Boolean
},
methods: {
onInput(evt) {
this.$emit('input', evt.target.value);
}
},
mounted() {
if (this.$slots.prefix) {
this.classes['input-with-prefix'] = true;
}
if (this.$slots.suffix) {
this.classes['input-with-suffix'] = true;
}
}
};
</script>
<style lang="scss">
.input-wrapper {
position: relative;
vertical-align: middle;
line-height: normal;
.input {
width: 100%;
height: 100px;
background-color: #f5f5f5;
border-radius: 10px;
padding-left: 60px;
padding-right: 60px;
font-size: 40px;
&.input-with-prefix {
padding-left: 60px;
}
&.input-with-suffix {
padding-right: 60px;
}
}
.input-prefix {
width: 60px;
height: 100%;
font-size: 40px;
text-align: center;
position: absolute;
left: 0;
top: 0;
z-index: 1;
display: flex;
justify-content: center;
align-items: center;
}
.input-suffix {
width: 60px;
height: 100%;
text-align: center;
position: absolute;
right: 0;
top: 0;
z-index: 1;
display: flex;
justify-content: center;
align-items: center;
}
}
</style>