mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
* [bugfix] CouponList always show empty info * [bugfix] add click feedback of buttons in components * [Doc] add custom theme document * [new feature] Notice bar support more props * [bugfix] PullRefresh test cases * [bugfix] unused NoticeBar style * [bugfix] Swipe width calc error * [Doc] english document of all action components * [Doc] change document site path to /zanui/vant * [Doc] fix * [bugfix] uploader style error * [bugfix] tabs document demo * [new feature] Cell support vue-router target route * [bugfix] add cell test cases * update yarn.lock * [bugfix] Tabbar cann't display info when use icon slot * [Doc] update document title * [bugfix] Dialog should reset button text when showed * [new feature] CouponList add showCloseButton prop * [new feature] Swipe add 'initialSwipe' prop * [bugfix] NoticeBar text disappeared when page back * [new feature] ImagePreview support startPosition * fix: improve imagePreview test cases * [bugfix] Steps style error when has more than 4 items * [new feature] normalize size of all icons * [new feature] Stepper add plus & minus event * fix: yarn.lock * [bugfix] addressEdit icon render failed
124 lines
2.7 KiB
Vue
124 lines
2.7 KiB
Vue
<template>
|
|
<div class="van-stepper" :class="{ 'van-stepper--disabled': disabled }">
|
|
<button
|
|
class="van-stepper__stepper van-stepper__minus"
|
|
:class="{ 'van-stepper__minus--disabled': isMinusDisabled }"
|
|
@click="onChange('minus')"
|
|
>
|
|
</button>
|
|
<input
|
|
type="number"
|
|
class="van-stepper__input"
|
|
:value="currentValue"
|
|
:disabled="disabled || disableInput"
|
|
@input="onInput"
|
|
>
|
|
<button
|
|
class="van-stepper__stepper van-stepper__plus"
|
|
:class="{ 'van-stepper__plus--disabled': isPlusDisabled }"
|
|
@click="onChange('plus')"
|
|
>
|
|
</button>
|
|
</div>
|
|
</template>
|
|
|
|
<script>
|
|
export default {
|
|
name: 'van-stepper',
|
|
|
|
props: {
|
|
value: {},
|
|
disabled: Boolean,
|
|
disableInput: Boolean,
|
|
min: {
|
|
type: [String, Number],
|
|
default: 1
|
|
},
|
|
max: {
|
|
type: [String, Number],
|
|
default: Infinity
|
|
},
|
|
step: {
|
|
type: [String, Number],
|
|
default: 1
|
|
},
|
|
defaultValue: {
|
|
type: [String, Number],
|
|
default: 1
|
|
}
|
|
},
|
|
|
|
data() {
|
|
let value = this.value ? +this.value : +this.defaultValue;
|
|
const correctedValue = this.correctValue(value);
|
|
if (value !== correctedValue) {
|
|
value = correctedValue;
|
|
this.$emit('input', value);
|
|
}
|
|
|
|
return {
|
|
currentValue: value
|
|
};
|
|
},
|
|
|
|
computed: {
|
|
isMinusDisabled() {
|
|
const min = +this.min;
|
|
const step = +this.step;
|
|
const currentValue = +this.currentValue;
|
|
return min === currentValue || (currentValue - step) < min || this.disabled;
|
|
},
|
|
isPlusDisabled() {
|
|
const max = +this.max;
|
|
const step = +this.step;
|
|
const currentValue = +this.currentValue;
|
|
return max === currentValue || (currentValue + step) > max || this.disabled;
|
|
}
|
|
},
|
|
|
|
watch: {
|
|
currentValue(val) {
|
|
this.$emit('input', val);
|
|
this.$emit('change', val);
|
|
},
|
|
|
|
value(val) {
|
|
val = this.correctValue(+val);
|
|
if (val !== this.currentValue) {
|
|
this.currentValue = val;
|
|
}
|
|
}
|
|
},
|
|
|
|
methods: {
|
|
correctValue(value) {
|
|
if (Number.isNaN(value)) {
|
|
value = this.min;
|
|
} else {
|
|
value = Math.max(this.min, value);
|
|
value = Math.min(this.max, value);
|
|
}
|
|
|
|
return value;
|
|
},
|
|
|
|
onInput(event) {
|
|
const val = +event.target.value;
|
|
this.currentValue = this.correctValue(val);
|
|
},
|
|
|
|
onChange(type) {
|
|
if ((this.isMinusDisabled && type === 'minus') || (this.isPlusDisabled && type === 'plus')) {
|
|
this.$emit('overlimit', type);
|
|
return;
|
|
}
|
|
|
|
const step = +this.step;
|
|
const currentValue = +this.currentValue;
|
|
this.currentValue = type === 'minus' ? (currentValue - step) : (currentValue + step);
|
|
this.$emit(type);
|
|
}
|
|
}
|
|
};
|
|
</script>
|