Vue金额监听按键过滤

<input :placeholder="'最高可提现金额:'+totalRevenue+'元'" v-model="drawMoney" @keypress="isNumber($event)">
methods: {
    isNumber(evt) {
      evt = (evt) ? evt : window.event;
      let charCode = (evt.which) ? evt.which : evt.keyCode;
      if ((charCode > 31 && (charCode < 48 || charCode > 57)) && charCode !== 46) {
        evt.preventDefault();
      } else {
        let idx = this.drawMoney.indexOf('.');
        (idx > 0) && (idx + 2 < this.drawMoney.length) && evt.preventDefault();
        console.log(this.drawMoney)
      }
    }
}
    原文作者:石头
    原文地址: https://segmentfault.com/a/1190000019694241
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞