Prechádzať zdrojové kódy

fix:解决货币输入组件双向绑定的问题

liuzl 3 rokov pred
rodič
commit
fdf22e8301
1 zmenil súbory, kde vykonal 2 pridanie a 8 odobranie
  1. 2 8
      src/components/currency/index.vue

+ 2 - 8
src/components/amountInput/index.vue → src/components/currency/index.vue

@@ -25,7 +25,7 @@
     props: {
       value: {
         type: [String, Number],
-        default: '',
+        default: '0',
       },
     },
     data() {
@@ -35,13 +35,11 @@
     },
     watch: {
       value(val) {
-        console.log(this.value)
         this.num = this.formatPrice(val)
       },
     },
 
     mounted() {
-      console.log(this.value)
       this.num = this.formatPrice(this.value)
     },
 
@@ -50,7 +48,6 @@
         this.$emit('input', this.num)
       },
       handleChange(val) {
-        console.log('val', val)
         this.$nextTick(() => {
           this.$emit('change', this.delcommafy(val))
         })
@@ -62,19 +59,16 @@
       },
       // 获得焦点金额去掉格式
       uninputMoney(el) {
-        console.log('el', el.target.value)
         if (el.target.value) {
           this.num = this.delcommafy(el.target.value)
         } else {
           this.num = null
         }
-        this.$emit('input', this.num)
       },
       //去除千分位中的‘,’
       delcommafy(num) {
         if (!num) return num
-        num = num.toString()
-        num = num.substring(1).replace(/,/gi, '')
+        num = num.toString().replace('¥', '').replace(/,/gi, '')
         if (num.indexOf('.00') > 0) num = parseInt(num)
         return num
       },