网站首页 > 文章精选 正文
今天给大家分享的是Vue3聊天实例中的朋友圈的实现及登录验证和倒计时操作。
先上效果图
这个是最新开发的vue3.x网页端聊天项目中的朋友圈模块。用到了ElementPlus组件库。
<!-- ……右侧发布模板 -->
<v3-layer v-model="isShowPublish" drawer="right" xclose z-index="1001" area="375px">
<template #content>
<div style="text-align:left;">
<div class="flexbox pt-20 pb-10">
<textarea class="flex1 ff-ar" name="content" placeholder="想记录点什么..." style="border:0;resize:none;height:60px;"></textarea>
</div>
<div class="vui-cell pt-10 pb-10">
<el-upload action="https://jsonplaceholder.typicode.com/posts/" list-type="picture-card" multiple :limit="8">
<i class="el-icon-plus"></i>
</el-upload>
</div>
<div class="pt-10">
<div class="vui-cell"><div class="flex1"><i class="iconfont icon-dingwei"></i><span class="fs-30 ml-20">你在哪里?</span></div><i class="iconfont icon-arrR c-999 fs-14"></i></div>
<div class="vui-cell"><div class="flex1"><i class="iconfont icon-mima"></i><span class="fs-30 ml-20">公开</span></div><i class="iconfont icon-arrR c-999 fs-14"></i></div>
</div>
<div class="align-c mt-30">
<div class="vui__btn vui__btn-primary"><i class="iconfont icon-send"></i> 发布</div>
</div>
</div>
</template>
</v3-layer>
使用了v3layer弹窗组件,内容区域是自定义插槽template模板。
另外朋友圈内容区滚动条是使用v3scroll美化滚动条组件来实现。
<v3-scroll>
滚动条内容区...
</v3-scroll>
图片预览使用到了element-plus的Image组件。
<el-image hide-on-click-modal
src="/assets/img/placeholder/xxx.jpg"
:preview-src-list="previewList"
/>
如下图:使用了vue3+vuex实现登录验证。
vue3注册form表单
<form @submit.prevent="handleSubmit">
<ul class="clearfix">
<li class="flexbox flex-alignc"><input class="iptxt flex1" type="text" v-model="formObj.tel" placeholder="请输入手机号" autocomplete="off" maxLength="11" /><em class="borLine"></em></li>
<li class="flexbox flex-alignc"><input class="iptxt flex1" type="password" v-model="formObj.pwd" placeholder="请输入密码" autocomplete="off" /><em class="borLine"></em></li>
<li class="flexbox flex-alignc"><input class="iptxt flex1" type="text" v-model="formObj.vcode" placeholder="验证码" autocomplete="off" /><em class="borLine"></em><button class="btn-getcode" @click.prevent="handleVcode" :disabled="disabled">{{vcodeText}}</button></li>
</ul>
<div class="btns"><button class="vui__btn vui__btn-primary btn__login" type="submit">注册</button></div>
<div class="lgregLink align-c clearfix">
<router-link class="navigator" to="/login">已有账号,去登录</router-link>
</div>
</form>
同样的通过getCurrentInstance来获取上下文,通过reactive来定义响应式数据。
<script>
import { reactive, toRefs, inject, getCurrentInstance } from 'vue'
export default {
setup() {
const { ctx } = getCurrentInstance()
const v3layer = inject('v3layer')
const utils = inject('utils')
const formObj = reactive({})
const data = reactive({
vcodeText: '获取验证码',
disabled: false,
time: 0,
})
const VTips = (content) => {
v3layer({
content: content, layerStyle: 'background:#ff5151;color:#fff;', time: 2
})
}
const handleSubmit = () => {
if(!formObj.tel){
VTips('手机号不能为空!')
}else if(!utils.checkTel(formObj.tel)){
VTips('手机号格式不正确!')
}else if(!formObj.pwd){
VTips('密码不能为空!')
}else if(!formObj.vcode){
VTips('验证码不能为空!')
}else{
ctx.$store.commit('SET_TOKEN', utils.setToken());
ctx.$store.commit('SET_USER', formObj.tel);
// ...
}
}
// 60s倒计时
const handleVcode = () => {
if(!formObj.tel) {
VTips('手机号不能为空!')
}else if(!utils.checkTel(formObj.tel)) {
VTips('手机号格式不正确!')
}else {
data.time = 60
data.disabled = true
countDown()
}
}
const countDown = () => {
if(data.time > 0) {
data.vcodeText = '获取验证码('+ data.time +')'
data.time--
setTimeout(countDown, 1000)
}else{
data.vcodeText = '获取验证码'
data.time = 0
data.disabled = false
}
}
return {
formObj,
...toRefs(data),
handleSubmit,
handleVcode
}
}
}
</script>
以上就实现了带60s倒计时的表单验证功能。
总体实现起来还是比较简单的,只是vue3和vue2写法有些不一样而已。
好了,以上就是vue3.0实现朋友圈及表单验证的相关分享,希望大家能喜欢~
猜你喜欢
- 2025-05-02 vue3跨层传递响应式数据及修改顶层数据
- 2025-05-02 前端面试必背——Vue.js中组件通信的几种方式及优缺点,附代码
- 2025-05-02 前端开发-Vite新时代构建工具(前端项目构建工具)
- 2025-05-02 Vue3 + Nest 实现权限管理系统 后端篇:如何在 NestJS 中使用 redis
- 2025-05-02 Web前端面试中,经常会被问到的Vue面试题
- 2025-05-02 Vue3中deep样式穿透的使用细节及源码解析
- 2025-05-02 基于uniapp+vue3跨端仿制chatgpt实例uniapp-chatgpt
- 2025-05-02 vue3 专用 indexedDB 封装库,基于Promise告别回调地狱
- 2025-05-02 Vue中mixin怎么理解?(vue mixins作用)
- 2025-05-02 在Vue中如何高效管理组件状态(vue 管理)
- 05-05MyBatis的三种分页方式,你学废了吗?
- 05-05如何写一个简单的分页(最简单的分页)
- 05-05详解如何使用Spring Data JPA进行数据的分页与排序
- 05-05手速太快引发分页翻车?前端竞态陷阱揭秘
- 05-05前端分页机制的具体实现(分页前端需要做什么)
- 05-05一个后勾腿动作,有效疏通血管,改善下肢发麻,促进全身燃脂
- 05-05大型调相机起动及并网研究(什么是调相机,与发电机区别)
- 05-05你们都是托:动态对比度其实是骗你的
- 最近发表
- 标签列表
-
- newcoder (56)
- 字符串的长度是指 (45)
- drawcontours()参数说明 (60)
- unsignedshortint (59)
- postman并发请求 (47)
- python列表删除 (50)
- 左程云什么水平 (56)
- 计算机网络的拓扑结构是指() (45)
- 稳压管的稳压区是工作在什么区 (45)
- 编程题 (64)
- postgresql默认端口 (66)
- 数据库的概念模型独立于 (48)
- 产生系统死锁的原因可能是由于 (51)
- 数据库中只存放视图的 (62)
- 在vi中退出不保存的命令是 (53)
- 哪个命令可以将普通用户转换成超级用户 (49)
- noscript标签的作用 (48)
- 联合利华网申 (49)
- swagger和postman (46)
- 结构化程序设计主要强调 (53)
- 172.1 (57)
- apipostwebsocket (47)
- 唯品会后台 (61)
- 简历助手 (56)
- offshow (61)