index_1.vue
1.19 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
<template>
<view class="ncc-num-range">
<u-input v-model="min" placeholder="最小值" type="number"></u-input>
<text class="separator">-</text>
<u-input v-model="max" placeholder="最大值" type="number"></u-input>
</view>
</template>
<script>
export default {
name: 'ncc-num-range',
model: {
prop: 'value',
event: 'input'
},
props: {
value: {
type: Array,
default: () => []
},
disabled: {
type: Boolean,
default: false
}
},
data() {
return {
min: '',
max: ''
}
},
watch: {
value(val) {
if (Array.isArray(val) && val.length === 2) {
this.min = val[0]
this.max = val[1]
} else {
this.min = ''
this.max = ''
}
},
min(val) {
this.onChange()
},
max(val) {
this.onChange()
}
},
methods: {
onChange() {
if ((!this.min && this.min !== 0) && (!this.max && this.max !== 0)) return this.$emit('input', [])
this.$emit('input', [this.min, this.max])
}
}
}
</script>
<style lang="scss" scoped>
.ncc-num-range {
width: 100%;
display: flex;
justify-content: space-between;
align-items: center;
.separator {
margin: 0 20rpx;
flex-shrink: 0;
}
}
</style>