input.vue
1.55 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
<template>
<div class="input-class">
<div class="wrapper-label" v-if="label">
<label class="input-label"> {{label}} </label>
<span class="error" v-if="showError">{{error}}</span>
</div>
<slot>
<input ref="input" class="wrapper-input" :placeholder="placeHolder" :value="inputValue" @input="onInputChange" @blur="validate"/>
</slot>
</div>
</template>
<script>
export default {
name: 'CInput',
props: {
value: {
type: [String, Number],
default() {
return '';
}
},
label: {
type: String,
default() {
return '';
}
},
placeHolder: {
type: String,
default() {
return '';
}
}
},
data() {
return {
inputValue: this.value,
error: '不能为空',
showError: false
};
},
methods: {
onInputChange() {
this.inputValue = this.$refs.input.value;
this.$emit('input', this.$refs.input.value);
},
setShowError(status = true) {
this.showError = status;
},
validate() {
if (!this.inputValue) {
this.showError = true;
return false;
} else {
this.showError = false;
return true;
}
}
}
};
</script>
<style lang="scss" scoped>
.input-label {
font-size: 36px;
display: inline-block;
font-weight: bold;
}
.wrapper-label {
margin-bottom: 30px;
}
.wrapper-input {
font-size: 28px;
width: 100%;
line-height: 1;
}
.error {
margin-left: 12px;
color: #d0021b;
}
::-webkit-input-placeholder {
color: #aaa;
}
</style>