为了防止通过网页频繁调取后台接口,可以加入倒计时限制
1 2 3 4 5 6 7 8 9 10 11
| <el-button link v-if="!img.isCode" @click="sendCode" >重新获取验证码</el-button>
<el-button style="margin-left: 30px" link v-if="img.isCode" >{{ img.codeTime }}s</el-button>
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| const img = reactive({ imgUrl : '/api/user/imgCode', codeTime: 60, isCode: false }) let clear = null
const sendCode = async () => { img.isCode = true img.imgUrl = '/api/user/imgCode?time=' +new Date() clear= setInterval(() => { img.codeTime--; if (img.codeTime === 0) { clearInterval(clear); img.codeTime = 60; img.isCode = false } }, 1000); }
|