封装方法countTotal(),传参n为当前需要处理的值,base为向上取整的基数
countTotal(n,base) {
const x = n % base
return x > 0 ? n - x + base : n
},
实例:
<el-input-number
v-model="diaObj.num"
:min="1"
size="medium"
:step="goodCase?goodCase:1"
@change="changeQuantity"
></el-input-number>
//监听库存输入值的变化方法
changeQuantity(value){
if(this.goodCase){
this.$nextTick(() => {
this.diaObj.num = this.countTotal(value,this.goodCase)
});
}else{
this.diaObj.num = value
}
},