移动端表格中使用input时type=number不生效

问题: 使用el-table和u-input组件做表格输入框时,需要对输入值做数字和小数校验,一开始想着使用type=number,可设置后移动端不兼容,故采input事件来校验,顺便记录一下动态列表格如何处理校验

<!-- html -->
<el-table :data="form.indicesTable" border style="width: 100%">
   <el-table-column label="业务指标" prop="yName" align="center">
     <template slot-scope="scope">
       <text style="fontSize:24rpx;"><text class="red" v-if="scope.row.isRequire==='1'">*</text>{{scope.row.yName}}</text>
     </template>
   </el-table-column>
   <el-table-column v-for="(item,index) in tableRowHead" align="center" :key="index" :label="item.lalel" :prop="item.value">
      <template slot-scope="scope">
         <u-input v-model.trim="scope.row[item.id]" maxlength="10" :clearable="true" placeholder="请输入" type="text" :border="false" @input="onInput(scope.$index,index)" />
      </template>
    </el-table-column>
</el-table>

// data
tableRowHead:[], // 列头数据
form:{
indicesTable:[] // 表格数据
}
// methods
// 数字和小数点和负号校验
 onInput(rowIndex, colIndex) { // type=number无效,所以用input事件
    let timer = setTimeout(() => { // 延迟执行,等待输入框的值更新
    this.tableRowHead.forEach((item, index) => { //this.tableRowHead是接口获取的动态列头数据
      if (colIndex == index) {
        this.form.indicesTable[rowIndex][item.id] = this.form.indicesTable[rowIndex][item.id].replace(/[^\d.]/g, '');
       }
    })
    clearTimeout(timer)
  }, 0);
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值