mirror of https://github.com/4xmen/xshop.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
106 lines
2.2 KiB
Vue
106 lines
2.2 KiB
Vue
6 months ago
|
<template>
|
||
|
<div id="inc">
|
||
|
<div class="btn btn-outline-danger" @click="dec">
|
||
|
<i class="ri-subtract-line"></i>
|
||
|
</div>
|
||
|
<input type="text" class="form-control"
|
||
|
v-model="val"
|
||
|
@keyup.up="inc"
|
||
|
@keyup.down="dec">
|
||
|
<div class="btn btn-outline-success" @click="inc">
|
||
|
<i class="ri-add-line"></i>
|
||
|
</div>
|
||
|
</div>
|
||
|
</template>
|
||
|
|
||
|
<script>
|
||
|
export default {
|
||
|
name: "inc",
|
||
|
components: {},
|
||
|
data: () => {
|
||
|
return {
|
||
|
val: 0,
|
||
|
}
|
||
|
},
|
||
|
emits: ['update:modelValue'],
|
||
|
props: {
|
||
|
modelValue: {
|
||
|
type: [Number, NaN],
|
||
|
default: NaN,
|
||
|
},
|
||
|
xvalue: {
|
||
|
type: Number,
|
||
|
default: 0
|
||
|
},
|
||
|
xmin: {
|
||
|
type: Number,
|
||
|
default: 0
|
||
|
},
|
||
|
xmax: {
|
||
|
type: Number,
|
||
|
default: 100
|
||
|
},
|
||
|
},
|
||
|
mounted() {
|
||
|
if (!isNaN(this.modelValue)) {
|
||
|
this.val = this.modelValue;
|
||
|
}else{
|
||
|
this.val = this.xvalue;
|
||
|
}
|
||
|
},
|
||
|
computed: {},
|
||
|
methods: {
|
||
|
inc(e){
|
||
|
e.preventDefault();
|
||
|
if (this.val < this.xmax){
|
||
|
this.val++;
|
||
|
}
|
||
|
},
|
||
|
dec(e){
|
||
|
e.preventDefault();
|
||
|
if (this.val > this.xmin){
|
||
|
this.val--;
|
||
|
}
|
||
|
}
|
||
|
},
|
||
|
watch: {
|
||
|
val(newValue) {
|
||
|
if (parseInt(this.val) > this.xmax){
|
||
|
this.val = this.xmax;
|
||
|
}
|
||
|
if (parseInt(this.val) < this.xmin){
|
||
|
this.val = this.xmin;
|
||
|
}
|
||
|
if (!isNaN(this.modelValue)) {
|
||
|
this.$emit('update:modelValue', newValue);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
</script>
|
||
|
|
||
|
<style scoped>
|
||
|
#inc {
|
||
|
display: grid;
|
||
|
grid-template-columns: 1fr 2fr 1fr;
|
||
|
direction: ltr;
|
||
|
}
|
||
|
|
||
|
#inc .form-control {
|
||
|
border-radius: 0;
|
||
|
text-align: center;
|
||
|
}
|
||
|
|
||
|
#inc div:first-child {
|
||
|
border-top-right-radius: 0;
|
||
|
border-bottom-right-radius: 0;
|
||
|
user-select: none;
|
||
|
}
|
||
|
|
||
|
#inc div:last-child {
|
||
|
border-top-left-radius: 0;
|
||
|
border-bottom-left-radius: 0;
|
||
|
user-select: none;
|
||
|
}
|
||
|
</style>
|