小程序短信4位6位验证码验证/vue也适用

4 篇文章 0 订阅
1 篇文章 0 订阅

这是张图片
如图我看有要这种需求的随便贴一下,随便看一下。有需要的根据自己的业务修改一下就OK了

`

  <div class="title">请输入验证码</div>
  <div class="conBox">
      <div class="concon">
        <block v-for="item in verCodeNumber" :key="index">
            <input 
            :value="inputValue.length >= index+1 ? inputValue[index] : '' "
            class='conNum' 
            disabled 
            @tap='Tap'
            ></input>
        </block>
      </div>
      <input 
          class="hiddenInput"
          type="number" 
          name="" 
          :maxlength="verCodeNumber" 
          v-model="inputValue" 
          bindinput="Focus"
          :focus="isFocus" 
          @input="!Focus"
      />
  </div>
  <div class="sendAgain" @click="handleClickSendAgainBtn">{{second}}</div>
</div>  

`

    data(){
      return{
          verCodeNumber:4,
          inputValue:"",
          isFocus:false,
          second:"",
          phoneNum:"",
          canClickAgainSend:true,
      }
    },
    watch:{
        inputValue(newValue){
            console.log(newValue)
            if(newValue == ""){ //为空 关闭键盘 失去焦点
              this.isFocus = false
            }else if(newValue.length >= this.verCodeNumber){//输入完成 关闭键盘 接口校验验证码
              this.isFocus = false
              this.mesCodeSendTest()
              console.log("输入完成")
            }
        }
    },
    mounted(){
      this.phoneNum = this.$root.$mp.query.phoneNum;
      this. startTiming();
      this.canClickAgainSend = false
    },
    methods:{
      Focus(e){
        console.log(e)
      },
      
      Tap(){
        this.isFocus = true
      },
      startTiming(){
          var that = this;
          this.$wxhttp.post({
            host:'app',
            url:'sendSmsCode',
            data: {
              phone:that.phoneNum,
              smsType:3
            },
          }).then((res)=>{
            console.log(res)
            that.canClickSendMessage = false;
            if(res.status != '000000')  {
                wx.showToast({
                    title: res.message,
                    icon: 'none',
                    duration: 1000
                })

                setTimeout(()=>{
                   wx.navigateBack({
                    delta: 1
                  })
                },1000)
            }else{
                var i = 60
                var timer = setInterval(()=>{
                    i--
                    that.second = i +"秒之后重新发送验证码"
                    if(i == 0){
                      that.second = '重新发送'
                      clearInterval(timer);
                       this.canClickAgainSend = true
                    }
                },1000)
            }

          })

      },
      handleClickSendAgainBtn(){
        this.startTiming()
      },
  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

老杨、

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值