欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 科技 > IT业 > VUE 开发——Vue学习(四)—— 智慧商城项目

VUE 开发——Vue学习(四)—— 智慧商城项目

2024/10/26 5:33:29 来源:https://blog.csdn.net/weixin_74113429/article/details/142962847  浏览:    关键词:VUE 开发——Vue学习(四)—— 智慧商城项目

api接口模块

将请求封装成方法,统一存放到api模块,与页面分离。
1.新建请求模块
src/api/login.js
2.封装请求函数

/* eslint-disable */ 
// 此处用于存放所有登录相关的接口请求
import request from '@/utils/request'//获取图片验证码
export const getPicCode = () => {return request.get('/captcha/image')
}

3.页面中导入调用

Toast轻提示

1.注册安装
2.使用方式:导入调用;通过this直接调用

短信验证倒计时

1.注册点击事件

 <button @click="getCode" >{{ second === totalSecond ? '获取验证码': second + '秒后重新发送' }}</button>

2.倒计时效果

//定时器没有开着并且second=totalsecondif ( !this.timer && this.second === this.totalSecond ) {//开启计时器this.timer = setInterval(() => {this.second--if (this.second <= 0) {clearInterval(this.timer)this.timer = null //重置定时器idthis.second = this.totalSecond}},1000)}

3.离开页面清除定时器

//离开页面时清除计时器destroyed () {clearInterval(this.timer)}

4.倒计时之前的校验处理

//验证手机号码是否正确validId () {if (!/^1[3-9]\d{9}$/.test(this.mobile)) {//进行弹窗提示this.$toast('请输入正确手机号')return false}return true}

5.封装短信验证请求。发送请求添加提示

//获取验证码
export const getMsgCode = (captchaCode, captchaKey, mobile) => {return request.get('/captcha/sendSmsCaptcha', {form: {captchaCode,captchaKey,mobile}})
}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com