两数字相加 若某项左侧首位是0 相加后并携带

在这里插入图片描述
1如图 取20相加 左侧是含0的右侧为自动生成的数
2在watch监听里处理代码
在这里插入图片描述
在这里插入图片描述

 'unclassed.docIdentity1':function (val, oldVal) {
  // 将数字转成数组便于遍历
 // let str = val.replace(/(?=(\B)(\d{1})+$)/g, ',')
 let str = val.replace(/(?=(\B)(\d{0})+$)/g, ',')
  let arr = [...str]
  // 如果一直输入用于清除存在的
  this.numBe=''
  this.zero=''

  arr.forEach((v,i)=>{
    // 0 改成变量 方便后面为0时进下面的数据
    if(v!=='0'){
      // 不为0时打开累计
      this.showNabo=true
      if(i===0){
        this.uuuu=String('')
      }
    }else {
    // 用于删除后看第一个为0则不走累加
      if(Number(v)===Number(i)){
        this.showNabo=false
      }
      // 当不为true也只能是最前面输入的0 后面在输入的会忽略
      if(this.showNabo==false){
        this.zero=this.zero+v
        this.uuuu=this.zero
      }
    }
    // 当进入循环赋值为true进入
    if(this.showNabo){
      this.numBe= this.numBe+v
      let matwe=JSON.parse(JSON.stringify(this.numBe))
      this.unclassed.docIdentity2=this.uuuu +( Number(this.unclassed.docIdentity)+Number(matwe))
    }

  })

},
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值