index.vue
1.28 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
<template>
<view class="zui-input">
<input v-model="model" :type="type" :disabled="disabled" :placeholder="placeholder" placeholder-class="zui-input__placeholder" @input="onInput" />
<view v-if="clearable && 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,
},
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);
},
onClear: function() {
this.model = '';
this.$emit('input', '');
this.$emit('clear');
}
}
}
</script>
<style lang="scss">
.zui-input {
display: flex;
width: 100%;
input {
flex: auto;
width: 100%;
}
&__placeholder {
color: $color-border;
}
&__close {
padding-left: $v-gap-sm;
color: $color-text-minor;
}
}
</style>