-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathu-input.vue
121 lines (108 loc) · 2.5 KB
/
u-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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<template>
<div :class="['u-input', { textarea: isTextArea }]" v-bind="$attrs">
<input
v-if="!isTextArea"
v-model="inputValue"
v-bind="$attrs"
v-on="listeners"
@input="onInput"
:disabled="disabled"
class="input"
/>
<textarea
v-else
v-model="inputValue"
v-bind="$attrs"
v-on="listeners"
@input="onInput"
:disabled="disabled"
class="input"
/>
</div>
</template>
<script>
export default {
name: 'u-input',
props: {
type: { type: String, default: 'text' },
value: { type: [String, Number] },
disabled: { type: Boolean, default: false }
},
data() {
return {
inputValue: this.value
}
},
computed: {
isTextArea() {
return this.type !== 'text'
},
listeners() {
const listeners = Object.assign({}, this.$listeners)
delete listeners['input']
return listeners
}
},
watch: {
value(val) {
this.inputValue = val
}
},
methods: {
onInput() {
this.$emit('update:value', this.inputValue) // allow sync api
this.$emit('input', this.inputValue) // allow v-model
}
}
}
</script>
<style lang="scss" scoped>
.u-input {
display: inline-block;
height: $component-height;
width: 300px;
&.textarea {
height: 200px;
}
&[size='s'] {
width: 120px;
}
&[size='l'] {
width: 400px;
}
.input {
width: 100%;
height: 100%;
font-size: 14px;
color: $input-color;
padding: 6px 10px;
border: 1px solid $border-color;
border-radius: 2px;
&[disabled] {
cursor: not-allowed;
}
&:focus {
border: 1px solid $primary-color;
}
/* 提示语统一样式 */
&:-ms-input-placeholder {
@extend .placeholder-text;
}
&:-moz-placeholder {
@extend .placeholder-text;
}
&::-moz-placeholder {
@extend .placeholder-text;
}
&::-webkit-input-placeholder {
@extend .placeholder-text;
}
.placeholder-text {
font-size: 14px;
color: $tip-color;
letter-spacing: 0;
line-height: 14px;
}
}
}
</style>