binDing.vue 1.16 KB
<template>
  <div>

    <mt-field label="手机号" placeholder="请输入正确的手机号" type="tel" v-model="phone" :attr="{ maxlength: 13 }"></mt-field>

    <mt-field label="验证码" v-model="codeText">
      <div class="getCode" @click="getCode">{{timeNum}}</div>
    </mt-field>

    <div style="margin-top: 34px" class="leftRightPadding">
      <van-button type="info" block>绑定</van-button>
    </div>
  </div>
</template>

<script>
export default {
  name: 'binDing',
  data() {
    return {
      codeText: '',
      phone: '',
      timeText: '获取验证码',
      timeNum: 60,
    }
  },
  created(){
    this.timeNum = this.timeText
  },
  methods: {
    getCode: function () {
      var _this = this
      // this.timeText = this.timeNum+'S'
      let Num = 5
      var timer = setInterval(function () {
        _this.timeNum = Num-- +'s'
        if(Num== -1){
          _this.timeNum = '获取验证码'
          clearInterval(timer)
        }
      }, 1000)
    }
  }
}
</script>

<style scoped lang="scss">
  .getCode {
    width: 100px;
    height: 48px;
    line-height: 48px;
    background: #ef4f4f;
    color: #fff;
    text-align: center;
  }
</style>