天天看點

input隻能輸入數字以及小數點後兩位

watch: {
            'query.amount' (n, o) {
                this.$nextTick(() => {
                  this.trimQuery('amount')
                    this.filterHandle(/[^\d.]/g, 'amount')
                  // this.filterHandle(/\.{2,}/g, 'amount')
                  // this.filterHandle(/^\./g, 'amount')
                  // this.filterHandle(/^[0]{2,}/g, 'amount')
                  //  this.filterHandle(/^[0]\d/g, 'amount')
                  // this.filterHandle(/\.\d{3,}/g, 'amount')
                      this.filterHandle3(/\.{2,}/g, 'amount')
                    this.filterHandle3(/^\./g, 'amount')
                    this.filterHandle3(/^[0]{2,}/g, 'amount')
                      this.filterHandle3(/^[0]\d/g, 'amount')
                    this.filterHandle3(/\.\d{3,}/g, 'amount')
                })
            },
        },
  filterHandle3 (reg, prop) {
               if(reg.test(this.query[prop])){
                 let str = this.query[prop].slice(0,-1)
                 this.$set(this.query, prop,str)
               }
              
            },
             filterHandle (re, prop) {
              this.$set(this.query, prop, this.query[prop].replace(re, ''))
            },
 trimQuery (prop) {
              this.$set(this.query, prop, this.query[prop].trim())
            },