当前位置:网站首页>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>
边栏推荐
- Summary of the first week
- Laravel服务容器(继承与事件)
- Fvuln-自动化web漏洞检测工具
- 【TypeScript】TypeScript中类型缩小(含类型保护)与类型谓词
- DAY15(DAY16拓展):文件包含漏洞
- php写一个购买全网最低价的纸尿裤
- Masscan使用教程.
- 改哭了,终于解决了Cannot read properties of undefined (reading ‘parseComponent‘)
- Merge the same items in the same column in table
- [C language series] - storage of deep anatomical data in memory (II) - floating point type
猜你喜欢
Liang Yuqi, founder of aitalk: the link between image and virtual reality
Summary of knowledge points related to forms and forms
About local variables
新手入门:手把手从PHP环境到ThinkPHP6框架下载
微信小程序-屏幕高度
[JS question solution] questions 1-10 in JS of niuke.com
表格与表单相关知识点总结
Build msys2 environment with win10
HCIA-R&S自用笔记(26)PPP
[C language series] - constants and variables that confuse students
随机推荐
【TypeScript】深入学习TypeScript对象类型
移动端-flex项目属性
焕然一新,swagger UI 主题更改
What is nmap and how to use it
Masscan tutorial
ClickHouse学习(三)表引擎
link与@import导入外部样式的区别
Wapiti是什么以及使用教程
如何 Pr 一个开源composer项目
Related knowledge of elastic box
弹性盒子相关知识
Provincial and urban three-level linkage (simple and perfect)
uniapp组件之tab选项卡滑动切换
QFrame类学习笔记
用sql-client.sh生成的job在cancle过后 如何实现断点续传?
Basic concepts of MySQL + database system structure + extended application + basic command learning
Day14: upload labs customs clearance tutorial
第五空间智能安全⼤赛真题----------PNG图⽚转换器
Common characteristic engineering operations
Seay source code audit system