当前位置:网站首页>Countdown of the uniapp component (such as the countdown to reading the agreement and the countdown to completing learning)
Countdown of the uniapp component (such as the countdown to reading the agreement and the countdown to completing learning)
2022-07-29 05:43:00 【Weisen】
One 、 Finally, the effect is achieved

Two 、 The realization of countdown
The main code of the timer is as follows :
// Countdown event (times Set the time for yourself , Here is 10)
countDownTime:function(){
var that = this;
if(that.times == 10){
that.sid = setInterval(function() {
that.times--;
if(that.times == 0){
// It's time to clear the timer
clearInterval(that.sid);
}
}, 1000);
}
},Be careful : During the countdown of the timer , The user may exit the page , At this time need Clear timer on exit , I need to use onUnload(), as follows :
// Back to the previous page , Clear timer , Prevent leaving this page , The timer is still running
onUnload() {
clearInterval(this.sid);
},3、 ... and 、 Switch between countdown and learned display
By setting two Boolean variables (timeshow、learned), adopt v-show To control its display and non display , The countdown is displayed in the countdown , After that, it shows that you have learned .
The front end :
<!-- Learning countdown is complete -->
<view v-show="timeshow" class="study-status-time">{
{times}}s</view>
<!-- Show learned -->
<view v-show="learned" class="study-status"> Have learned </view>js part :
// Countdown event
countDownTime:function(){
var that = this;
if(that.times == 10){
that.sid = setInterval(function() {
that.times--;
if(that.times == 0){
clearInterval(that.sid);
that.timeshow=false;
that.learned=true;
// The prompt box pops up
uni.showToast({
title:' The article has been learned ',
icon:'none',
duration:2000
})
}
}, 1000);
}
},Four 、 Complete code
<template>
<view class="study-content">
<!-- Article title -->
<view class="article-index-title"> Article title </view>
<!-- Article content -->
<view class="article-content"> Article content </view>
<!-- Learning completion and experience filling -->
<view class="content-bottom">
<view class="content-bootom-item">
<!-- Learning experience fill -->
<view class="idea-input" @click="inputideal()" ><span> Fill in the learning experience </span></view>
<!-- Learning countdown is complete -->
<view v-show="timeshow" class="study-status-time">{
{times}}s</view>
<!-- Show learned -->
<view v-show="learned" class="study-status"> Have learned </view>
</view>
</view>
</view>
</template>
<script>
export default {
data() {
return {
times:10,
timeshow:true,
learned:false,
}
},
// The countdown method is executed at the beginning of the page
onLoad() {
this.countDownTime()
},
// Back to the previous page , Clear timer , Prevent leaving this page , The timer is still running
onUnload() {
clearInterval(this.sid);
},
methods: {
// Countdown event
countDownTime:function(){
var that = this;
if(that.times == 10){
that.sid = setInterval(function() {
that.times--;
if(that.times == 0){
clearInterval(that.sid);
that.timeshow=false;
that.learned=true;
// The prompt box pops up
uni.showToast({
title:' The article has been learned ',
icon:'none',
duration:2000
})
}
}, 1000);
}
},
// Click the input experience box , If it is not completed, it will prompt that there are still a few seconds , You can enter
inputideal:function(){
if(this.times!=0){
uni.showToast({
title:' also '+this.times+' Seconds can be filled in ',
icon:'none',
duration:2000
})
return
}
}
}
}
</script>
<style>
.study-content{
width: 100%;
height: 100%;
}
.article-index-title{
padding: 30rpx 40rpx 20rpx 40rpx;
font-size: 40rpx;
font-weight: 600;
text-align: justify;
}
.article-content{
box-sizing: border-box;
padding-left: 40rpx;
padding-right: 40rpx;
overflow: hidden;
font-size: 32rpx;
width: 100%;
text-align: justify;
line-height: 1.8;
padding-bottom: 50rpx;
}
.content-bottom{
height: 120rpx;
width: 100%;
position: fixed;
bottom: 0;
border-top: 1px #f0f0f0 solid;
background-color: #ffffff;
z-index: 100;
}
.content-bootom-item{
margin-left: 20rpx;
margin-right: 20rpx;
display: flex;
justify-content: space-between;
}
.idea-input{
width: 75%;
background-color: #f0f0f0;
height: 80rpx;
margin-top: 20rpx;
border-radius: 20rpx;
display: flex;
align-items: center;
}
.idea-input span{
color: #8b8b8b;
margin-left: 20rpx;
}
.study-status{
width: 20%;
background-color: #0055ff;
height: 80rpx;
margin-top: 20rpx;
border-radius: 20rpx;
display: flex;
align-items: center;
justify-content: center;
color: #ffffff;
}
.study-status-time{
width: 20%;
background-color: #8f8f8f;
height: 80rpx;
margin-top: 20rpx;
border-radius: 20rpx;
display: flex;
align-items: center;
justify-content: center;
color: #ffffff;
}
</style>
边栏推荐
- 微信小程序-屏幕高度
- Introduction to C language array to proficiency (array elaboration)
- link与@import的关系
- 【无标题】
- Related knowledge of elastic box
- ClickHouse学习(四)SQL操作
- Wechat applet - component parameter transmission, state management
- Solve the problem that the prompt information of form verification does not disappear and the assignment does not take effect
- Similarities and differences between REM and PX and EM
- Win10 搭建MSYS2环境
猜你喜欢

Hcia-r & s self use notes (24) ACL

DAY4:SQL Sever 简单使用

微信小程序-组件传参,状态管理

Masscan使用教程.

Thinkphp6管道模式Pipeline使用

Hcia-r & s self use notes (27) comprehensive experiment
![Niuke network programming problem - [wy22 Fibonacci series] and [replace spaces] detailed explanation](/img/39/1d4fb1774b0f9f7c9bb13221f0d6c2.png)
Niuke network programming problem - [wy22 Fibonacci series] and [replace spaces] detailed explanation

ClickHouse学习(四)SQL操作

What is sqlmap and how to use it

Set the background color of a cell in the table
随机推荐
Question swiping Madness - leetcode's sword finger offer58 - ii Detailed explanation of left rotation string
Clickhouse learning (VIII) materialized view
Playwright实战案例之爬取js加密数据
【TypeScript】TypeScript中类型缩小(含类型保护)与类型谓词
Go|Gin 快速使用Swagger
uniapp组件之倒计时(如阅读协议倒计时、完成学习倒计时)
个人学习笔记
第五空间智能安全⼤赛真题----------PNG图⽚转换器
php写一个购买全网最低价的纸尿裤
Fvuln automated web vulnerability detection tool
dcat 批量操作弹窗及参数传递
Clickhouse learning (IX) Clickhouse integrating MySQL
[C language series] - constants and variables that confuse students
[typescript] learn typescript object types in depth
Clickhouse learning (IV) SQL operation
uniapp之常用提示弹框
DAY14:Upload-labs 通关教程
ClickHouse学习(二)ClickHouse单机安装
Flask 报错 RuntimeError: The session is unavailable because no secret key was set.
Laravel服务容器(上下文绑定的运用)