1、javascript实现倒计时
实现的思路: 一个setInterval对象。在setInterval中将全局的时间变量减一,然后vue会触发页面更新。在渲染的时候将时间戳经过过滤器生成:小时:分钟:秒
的格式。
1.1 启动计时
1 | startCount() { |
1.2 时间更新函数
时间更新函数除了将全局的时间戳减一之外。还可以进行一些业务操作。比如说每隔一段时间的将数据发送到后台。
1
2
3
4
5
6
7
8
9
10
11
12
13
14 updateTime() {
// console.log('updated')
this.remainTime = this.remainTime - 1
if (this.remainTime === 0) {
this.$message({
type: 'warn',
message: '考试结束时间到'
})
// 清空计时器
clearInterval(this.intervalId)
// 提交数据
this.submit()
}
},
1.3 时间戳过滤器
将整型的时间戳转换成时间hours:minutes:second格式
1 | filters: { |
效果:
去除csdn登录框
1 | (function() { |
知乎去除网页登录框
1 | // ==UserScript== |