1. 程式人生 > >vue獲取驗證碼

vue獲取驗證碼

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Vue起步學習</title>
    <script src="./js/vue.min.js"></script>
</head>
<style type="text/css">

</style>
<body>
    <p id="root"><input type="text" placeholder
="圖片驗證碼">
<i @click="getCode">
{{yzm}}</i></p> </body> </html> <script type="text/javascript"> new Vue({ el: '#root', data(){ return{ yzm:'獲取驗證碼' } }, methods:{ getCode:function()
{
if(this.yzm=='獲取驗證碼'){ const TIME_COUNT = 5; if (!this.timer) { this.yzm = TIME_COUNT; this.show = false; this.timer = setInterval(() => { if
(this.yzm > 0 && this.yzm <= TIME_COUNT) { this.yzm--; } else { this.show = true; clearInterval(this.timer); this.timer = null; }if (this.yzm ==0){ this.yzm="獲取驗證碼" } }, 1000) } } } } })
</script>

這裡寫圖片描述