
限購(gòu).png
開發(fā)中,碰到一個(gè)需求,當(dāng)步進(jìn)器增加的數(shù)量達(dá)到10時(shí),再點(diǎn)擊加號(hào)按鈕,就要提示“超出限購(gòu)數(shù)量”,所以打算使用van-stepper的overlimit(點(diǎn)擊不可用的按鈕時(shí)觸發(fā))事件。但是發(fā)現(xiàn)不好區(qū)分是加號(hào)還是減號(hào)觸發(fā)的overlimit,文檔也沒(méi)寫overlimit有什么參數(shù)。

van-stepper文檔.png
然后點(diǎn)擊源碼看了一下,原來(lái)overlimit事件是有一個(gè)type參數(shù)的,這樣就好解決了。

van-stepper源碼.png
<template>
<div>
<van-stepper
v-model="value"
:min="1"
:max="10"
@overlimit="showMaxLimitAlert"
></van-stepper>
</div>
</template>
<script>
import { Toast } from "vant";
export default {
data() {
return {
value: 1,
};
},
methods: {
showMaxLimitAlert(type) {
if (type === 'plus') {
Toast("已經(jīng)是最大值了");
}
if (type === 'minus') {
Toast("已經(jīng)是最小值了");
}
},
},
};
</script>