第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定

基于 elementUI 二次封裝的 Format 輸入框 組件

標簽:
Vue.js

最近封装了一个可以自带format的输入框组件,效果如下:

https://img1.sycdn.imooc.com//5bd95df40001c98103640053.jpg

我所封装的组件代码如下:

<template>
  <div>
    <el-input v-model="startValue"
         @blur="startInput" 
         :maxlength="maxlength"></el-input>
    <i class="el-icon-minus padding-top-5"></i>
    <el-input v-model="endValue"
          @blur="endInput" 
          :maxlength="maxlength"></el-input>
  </div>
</template>

<script>
export default {
  name: "input-format-range",
  props:['startName','endName','maxlength'],
  data:()=>({
    startValue:'',
    endValue:''
  }),
  methods:{
    checkInput({value}){
      value=value?parseFloat(value.toString().replace(/[^0-9._-]/g, ''))||0:'';
      let formattedValue = '';
      if (value !== 0 && value !== '')
          formattedValue = Number(value)
                   .toFixed(2)
                   .replace(/\d{1,3}(?=(\d{3})+(\.\d*)?$)/g,'$&,');
       else
        formattedValue = value;
        
      return formattedValue;
    },
    startInput({target}){
      this.startValue = this.checkInput(target);
      this.$emit('checkInput',{startValue:this.startValue,
                               startName:this.startName,
                               endValue:this.endValue,
                               endName:this.endName});
    },
    endInput({target}){
      this.endValue = this.checkInput(target);
      this.$emit('checkInput',{startValue:this.startValue,
                               startName:this.startName,
                               endValue:this.endValue,
                               endName:this.endName});
    }
  }
}
</script>

如果传给后台要纯数字类型,你还需要去掉里面的逗号,你可以在main.js里面定义如下函数:

Vue.prototype.splitValue = function (value) {
  value = value? parseFloat(value.replace(/,/g ,'')) || 0 : '';
  return value
};

在父组件中就可以愉快的使用了~:

<template>
      <inputFormatRange @checkInput="checkPrice"
                :maxlength="9"
                :startName="'costPriceFrom'"
                :endName="'costPriceTo'"></inputFormatRange>
</template>

<script>
import inputFormatRange from '@/components/inputFormatRange.vue'
export default {
  name: "price-manage",
  components:{inputFormatRange},
  data:()=>({
    getTable:{
      costPriceFrom: '',
      costPriceTo: ''
     }
  }),
  methods:{
    checkPrice(obj){
      this.getTable[obj.startName] = this.splitValue(obj.startValue);
      this.getTable[obj.endName] = this.splitValue(obj.endValue);
    }
  }
}
</script>


點擊查看更多內容
TA 點贊

若覺得本文不錯,就分享一下吧!

評論

作者其他優(yōu)質文章

正在加載中
  • 推薦
  • 評論
  • 收藏
  • 共同學習,寫下你的評論
感謝您的支持,我會繼續(xù)努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦
今天注冊有機會得

100積分直接送

付費專欄免費學

大額優(yōu)惠券免費領

立即參與 放棄機會
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號

舉報

0/150
提交
取消