不多BB,直接上代码:
<template>
<div>
<el-button type="info" round @click="getCode" :disabled="used">{{Text3}}</el-button>
</div>
</template>
<script>
import md5 from 'js-md5';
export default {
name: "JsMd5",
data(){
return{
counter:60,
Text3:'获取验证码',
used:false,
}
},
methods:{
getCode(){
var timeWare = window.setInterval(() => {
this.used = true;
this.counter -- ;
this.Text3 = this.counter + 's后重新获取';
if (this.counter === 0){
this.Text3 = '获取验证码';
this.counter = 60;
this.used = false;
clearTimeout(timeWare);
}
},1000);
}
}
}
</script>
允许结果:
倒计时期间按钮不可点击
ok,结束,又水了一波,如果有错,欢迎指正,如果不懂,欢迎留言