广告
返回顶部
首页 > 资讯 > 前端开发 > JavaScript >vue实现通过手机号发送短信验证码登录的示例代码
  • 508
分享到

vue实现通过手机号发送短信验证码登录的示例代码

2024-04-02 19:04:59 508人浏览 独家记忆
摘要

本文主要介绍了Vue实现通过手机号发送短信验证码登录的示例代码,分享给大家,具体如下: <template> <div class="get-mobile

本文主要介绍了Vue实现通过手机号发送短信验证码登录的示例代码,分享给大家,具体如下:

<template>
    <div class="get-mobile" @touchmove.prevent>
        <div class="main">
            <div class="pt-20 pr-15 pl-15 pb-20">
                <input class="input mb-15" v-model="fORM.tel" placeholder="请输入手机号" type="number">
                <div class="box">
                    <input class="input" v-model="form.telVerificationCode" placeholder="请输入短信验证码" type="number">
                    <div class="el-button" @click="send">{{ countDown }}</div>
                </div>
            </div>
            <div class="btn" @click="sumbit">提交</div>
        </div>
    </div>
</template>

<script>
import { sendLoginMsGCode, login } from 'xx';

export default {
    name: 'GetMobile',
    data() {
        return {
            form: {
                telVerificationCode: '',
                tel: '',
            },
            countDown: "发送验证码", // 倒计时
            bVerification: false // 节流
        }
    },
    methods: {
        async sumbit() {
            const { telVerificationCode, tel } = this.form
            if (!telVerificationCode || !tel) return this.$toast("请输入手机号和验证码");
            let { code, data } = await login({
                tel,
                telVerificationCode,
                isOffline: false
            });
            if (code === 200) {
                this.$toast('登录成功');
                this.$emit('sumbit', data.userInfo);
                this.$emit('update:dialog', false)
            }
        },
        async send() {
            if (!/^\d{11}$/.test(this.form.tel)) return this.$toast("请先输入正确的手机号");
            if (this.bVerification) return;
            this.bVerification = true;
            const { code } = await sendLoginMsgCode({
                tel: this.form.tel
            });
            if (code === 200) {
                this.$toast("发送验证码...");
            }
            let countDown = 59;
            const auth_time = setInterval(() => {
                this.countDown = countDown--;
                if (this.countDown <= 0) {
                    this.bVerification = false;
                    this.countDown = "发送验证码";
                    clearInterval(auth_time);
                }
            }, 1000);
        }
    }
}
</script>

<style lang='sCSS' scoped>
.get-mobile {
    height: 100vh;
    width: 100vw;
    background-color: rgba(0, 0, 0, .6);
    display: flex;
    justify-content: center;
    align-items: center;

    .main {
        width: 280px;
        height: 178px;
        background: #FFFFFF;
        border-radius: 5px;

        .input {
            border: 1px solid #EBEBEF;
            border-radius: 5px;
            height: 40px;
            padding-left: 10px;
        }

        .el-button {
            margin-left: 10px;
            border-radius: 5px;
            background: #5F93FD;
            color: #fff;
            width: 140px;
            display: flex;
            justify-content: center;
            align-items: center;
        }

        .btn {
            height: 45px;
            color: #5F93FD;
            display: flex;
            justify-content: center;
            align-items: center;
            border-top: 1px solid #EBEBEF;
        }
    }
}
</style>

到此这篇关于vue实现通过手机号发送短信验证码登录的示例代码的文章就介绍到这了,更多相关vue 验证码登录内容请搜索编程网以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程网!

--结束END--

本文标题: vue实现通过手机号发送短信验证码登录的示例代码

本文链接: https://www.lsjlt.com/news/149761.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作