700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > vue实现验证码倒计时功能

vue实现验证码倒计时功能

时间:2022-07-22 02:11:04

相关推荐

vue实现验证码倒计时功能

web前端|js教程

倒计时,功能,验证

web前端-js教程 上网上搜了一下,也把他们的代码试了一下,自己出了很多问题。所以,需要写一篇基础入门的文章,避免后面人采坑。

lebishop 源码,vscode配置c语言界面,ubuntu 开启ssd,tomcat怎么选择版本,反爬虫ast,php 自带加密解密,湖南seo优化多少钱,教育资料网站源码,dj网站模板下载工具lzw

这是按照网上写的HTML页面

一笔画游戏源码,ubuntu可重装吗,tomcat面试必考题,php视频爬虫,php后端需要加班吗,江北seo企业lzw

春节祝福网页源码,vscode最好用的颜色主题,ubuntu安装巡风,tomcat设置站名,网页爬虫 交通,php手机论坛源码,徐州seo优化需要多少钱,aspx网站下载lzw

发送验证码 {{count}} s

注册

js写成

data(){ return { show: true, count: \, timer: null, }},methods:{ getCode(){ const TIME_COUNT = 60; if (!this.timer) {this.count = TIME_COUNT;this.show = false;this.timer = setInterval(() => { if (this.count > 0 && this.count <= TIME_COUNT) {this.count--; } else {this.show = true;clearInterval(this.timer);this.timer = null; }}, 1000) } } }

发现浏览器一直报错Uncaught SyntaxError: Unexpected token {

所以按照官方文档的格式,把js的结构改成

new Vue({ el:.register-pannel, data:{ show:true, timer:null, count:\ }, methods:{ getCode(){ this.show = false; const TIME_COUNT = 60; if (!this.timer) { this.count = TIME_COUNT; this.show = false; this.timer = setInterval(() => { if (this.count > 0 && this.count <= TIME_COUNT) {this.count--;} else {this.show = true;clearInterval(this.timer);this.timer = null;} }, 1000)} } }});

于是格式是没有问题了,但是样式并没有生效。变成了另一个样子。

上网上搜了很多。

有说是js引用顺序的问题。

有说是将js写进window.onload的。试了一下,发现都不对。

后来,在官方文档中发现了el属性:为实例提供挂载元素。值可以是 CSS 选择符,或实际 HTML 元素,或返回 HTML 元素的函数。

所以改成

new Vue({ el:.register-pannel, //注册p的class data:{show:true, timer:null, count:\ }, methods:{ getCode(){ this.show = false; const TIME_COUNT = 60;if (!this.timer) { this.count = TIME_COUNT; this.show = false; this.timer = setInterval(() => { if (this.count > 0 && this.count <= TIME_COUNT) { this.count--; } else { this.show = true; clearInterval(this.timer); this.timer = null; } }, 1000) } } } });

效果就出来了。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。