当前位置: 首页 > article >正文

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=totalsecond
        if ( !this.timer && this.second === this.totalSecond ) {
            //开启计时器
            this.timer = setInterval(() => {
                this.second--

                if (this.second <= 0) {
                    clearInterval(this.timer)
                    this.timer = null //重置定时器id
                    this.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
    }
  })
}

http://www.kler.cn/news/356401.html

相关文章:

  • Javascript中的堆内存和栈内存
  • mysql--数据类型
  • 前端vue项目使用Decimal.js做加减乘除求余运算
  • C++20中头文件source_location的使用
  • 大数据学习-Clickhouse
  • 数据结构——链表,哈希表
  • makefile和make
  • JavaWeb学习(3)
  • [项目详解][boost搜索引擎#1] 概述 | 去标签 | 数据清洗 | scp
  • 024 elasticsearch集群
  • 生财合伙人推荐 - 鞠海深-群控
  • 霍夫圆型硬币检测Matlab程序
  • GitHub与GitCode
  • vuefor循环动态展示图片不显示
  • ARM指令集和汇编语言的关联学习
  • 设计模式——代理模式(6)
  • 408算法题leetcode--第33天
  • 【概率论】泊松分布
  • Gorm操作数据库,有和没有WithContext的区别
  • 【设计模式】深入理解 Python 单例模式:从原理到实现