利用element-ui编写一个表单金额输入框

  介绍

这篇文章给大家介绍利用element-ui编写一个表单金额输入框,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。

组件代码如下:

,,},   ,,规则:{   ,,,类型:对象,   ,,默认值:,(),=祝辞,{,},   ,,},   },   ,data  (), {   return {才能   ,,,showFormatPrice:假的,,//,是否显示遮罩   ,,}   },   ,计算:{   formaterPrice 才能;(),{   ,,if  (   ,,,this.form.deceivedAmount  !==, & # 39; & # 39;,,,   ,,,this.form.deceivedAmount  !==零   ,,),{   ,,,//,去掉前面的0   ,,,const  integer =, this.form.deceivedAmount.split(& # 39; # 39;公司)[0]   ,,,const  decimal =, this.form.deceivedAmount.split(& # 39; # 39;公司)[1]   ,,,,?,’。$ {this.form.deceivedAmount.split(& # 39; # 39;公司)[1]}”   ,,,,,,& # 39;& # 39;   ,,,return ,“${整数   ,,,,.toString ()   ,,,,.replace (/(?=(? ! ^) (\ d {3}) + $)/g, & # 39;, & # 39;)} ${十进制}'   ,,},{else    ,,,return  & # 39; & # 39;   ,,}   ,,},   },   ,方法:{//,才能聚焦金额输入框   focusInput 才能;(),{   ,,this.showFormatPrice =false   这。才能refs.input.focus美元()   ,,},//才能,失焦金额输入框   blurInput 才能;(),{   ,,if  (this.form.deceivedAmount  !==, & # 39; & # 39;), {   ,,,//,去掉前面的0   ,,,const  integer =,数量(this.form.deceivedAmount.split(& # 39; # 39;公司)[0])   ,,,const  decimal =, this.form.deceivedAmount.split(& # 39; # 39;公司)[1]   ,,,,?,’。$ {this.form.deceivedAmount.split(& # 39; # 39;公司)[1]}”   ,,,,,,& # 39;& # 39;   ,,,this.form.deceivedAmount =, isNaN(“${整数}${十进制}”)   ,,,,? this.form.deceivedAmount   ,,,,:,“${整数}${十进制}”   ,,,if  (typeof  this.rules [this.prop] [0] .pattern  !==, & # 39;对象# 39;),{   ,,,,throw “请确保,规则[$ {this.prop}] [0] .pattern 为正则表达式的   ,,,,回来   ,,,}   ,,,this.showFormatPrice =, this.rules [this.prop] [0] .pattern.test (   ,,,,this.form.deceivedAmount,   ,,,)   ,,}   ,,},   },   }   & lt;/script>      & lt; style  lang=發ess", scoped>   .price-mask  {   ,位置:绝对;   ,z - index: 2;   ,:1 px;   ,左:125 px;   ,背景:白色;   ,宽度:110 px;   ,溢出:汽车;   ,字体大小:13 px;   }   & lt;/style>

在表单中的使用方法其实和你直接写一个<代码> el-form-item> //,使用方法:   & lt; template  lang=皃ug"祝辞   el-form(:模型=癴orm", ref=癴orm",标签=?80 px",: label-suffix=? # 39;: & # 39;“,:规则=皉ules")   priceInput才能(:form.sync =,“form",: width =,“150“, label =,“金额“,prop =,“deceivedAmount",: rules =,“rules")   & lt;/template>      & lt; script>   import  priceInput 得到& # 39;@self/组件/priceInput& # 39;   数据(),{   ,return  {   ,,形式:{   ,,,deceivedAmount:空,   ,,},   ,,规则:{   ,,deceivedAmount:,   ,,,{   ,,,,模式:,/^ 1000000000美元| ^ 1000000000.0美元| ^ 1000000000.00美元| ^ [+]{0,1}(\ d {0 9}) $ | ^ [+] {0,1} (\ d {0 9} \ \ d{1,2})/美元,   ,,,,的信息:,& # 39;,请输入,清廉亿,的正数,可保留两位小数& # 39;,   ,,,,触发:,& # 39;模糊# 39;   ,,,},   ,,,,   ,,},   ,}   }   组件:{   priceInput,   }   & lt;/script>

关于利用element-ui编写一个表单金额输入框就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看的到。

利用element-ui编写一个表单金额输入框