vue关于input输入金额,只能限制输入数字和一位小数点(Vue for the input amount, only numbers and one decimal point can be limited)

            <a-input
                suffix="元"
                placeholder="输入金额"
                @change="(e) => {e.target.value = getMoney(e.target.value)}"
                v-decorator="['rechargeAmount']"
                @blur="getRechargeNum($event.target.value)"/>

  方法

getMoney (value) { // 价格的限制规则,只能输入小数点后两位
      value = value.replace(/[^\d.]/g, '')// 清除"数字"和"."以外的字符
      value = value.replace(/^\./g, '')// 验证第一个字符是数字而不是字符
      value = value.replace(/\.{2,}/g, '.')// 只保留第一个.清除多余的
      value = value.replace('.', '$#$').replace(/\./g, '').replace('$#$', '.')
      value = value.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3')// 只能输入两个小数
      return value
    },

  vue里的加减法计算,不能直接加减,因为是字符串形式

      const that = this
      const { form: { validateFields } } = this
      var serviceChargeAmount = this.form.getFieldValue('serviceChargeAmount')
      var refundAmount = this.form.getFieldValue('refundAmount')
      var totalAmount = parseInt(serviceChargeAmount) + parseInt(refundAmount)
      if(parseInt(this.memberOrder.balance)<totalAmount){
        return that.$message.error('手续费+退款金额>余额,请重新输入!')
      }
————————
            <a-input
                suffix="元"
                placeholder="输入金额"
                @change="(e) => {e.target.value = getMoney(e.target.value)}"
                v-decorator="['rechargeAmount']"
                @blur="getRechargeNum($event.target.value)"/>

Method

getMoney (value) { // 价格的限制规则,只能输入小数点后两位
      value = value.replace(/[^\d.]/g, '')// 清除"数字"和"."以外的字符
      value = value.replace(/^\./g, '')// 验证第一个字符是数字而不是字符
      value = value.replace(/\.{2,}/g, '.')// 只保留第一个.清除多余的
      value = value.replace('.', '$#$').replace(/\./g, '').replace('$#$', '.')
      value = value.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3')// 只能输入两个小数
      return value
    },

The addition and subtraction method in Vue cannot be added or subtracted directly, because it is in the form of string

      const that = this
      const { form: { validateFields } } = this
      var serviceChargeAmount = this.form.getFieldValue('serviceChargeAmount')
      var refundAmount = this.form.getFieldValue('refundAmount')
      var totalAmount = parseInt(serviceChargeAmount) + parseInt(refundAmount)
      if(parseInt(this.memberOrder.balance)<totalAmount){
        return that.$message.error('手续费+退款金额>余额,请重新输入!')
      }