index.vue
2.06 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
94
95
96
<template>
<view class="zui-input">
<input class="input" v-model="model" :type="type" :disabled="disabled" :placeholder="placeholder"
:maxlength="maxlength" placeholder-class="zui-input__placeholder" @input="onInput" @blur="onBlur" @focus="onFocus" :style="{backgroundColor
: flag && !disabled ? '#f5f7fa' : '',borderRadius
: flag && !disabled ? '5px' : ''}"/>
<view v-if="clearable && !disabled && ![undefined, null, ''].includes(model)" class="zui-input__close"
@click="onClear">
<zui-icon name="close"></zui-icon>
</view>
</view>
</template>
<script>
import ZuiIcon from '../icon/index.vue';
export default {
components: {
ZuiIcon,
},
props: {
value: [String, Number],
type: {
type: String,
default: 'text'
},
placeholder: {
type: String,
default: '请输入'
},
clearable: Boolean,
disabled: Boolean,
maxlength: {
type: Number,
default: 99
},
flag: {
type: Boolean,
default: false
}
},
data: function() {
return {
model: this.value,
}
},
watch: {
value: function(val) {
this.model = val;
}
},
methods: {
onInput: function(e) {
const value = e.detail.value;
this.$emit('input', value);
},
onBlur: function(e) {
const value = e.detail.value;
this.$emit('blur', value);
},
onClear: function() {
this.model = '';
this.$emit('input', '');
this.$emit('clear');
},
onFocus: function() {
this.$emit('focus')
}
}
}
</script>
<style lang="scss">
.zui-input {
display: flex;
width: 100%;
.input {
flex: auto;
width: 100%;
font-size: inherit;
}
&__placeholder {
color: $color-text-placeholder;
font-weight: normal;
}
&__close {
padding-left: $padding-xs;
color: $color-text-minor;
display: inline-flex;
align-items: center;
}
}
</style>