如何设置二维码的时效性?(设置过期时间)
很多二维码都需要设置过期时间,比如扫码登录、付款二维码等。下面编程教程网小编给大家详细介绍一下实现代码!
具体代码如下:
export default {
name: "qrCode",
data() {
return {
codeStatus: 1, // 1- 未扫码 2-扫码通过 3-过期
effectiveTime: 30, // 有效时间
qrCodeTimer: null // 有效时长计时器
uid: '',
time: ''
};
},
methods: {
// 轮询获取二维码状态
getQcodeStatus() {
if(!this.qsCodeTimer) {
this.qrCodeTimer = setInterval(()=> {
// 二维码过期
if(this.effectiveTime <=0) {
this.codeStatus = 3
clearInterval(this.qsCodeTimer)
this.qsCodeTimer = null
return
}
this.effectiveTime--
}, 1000)
}
},
// 刷新二维码
refreshCode() {
this.codeStatus = 1
this.effectiveTime = 30
this.qsCodeTimer = null
this.generateORCode()
}
},
以上是编程学习网小编为您介绍的“如何设置二维码的时效性?(设置过期时间)”的全面内容,想了解更多关于 vuejs 内容,请继续关注编程基础学习网。