美文网首页Vue精彩案例、教程
vue判断用户在页面停留时间是否超时

vue判断用户在页面停留时间是否超时

作者: lesdom | 来源:发表于2018-10-16 22:39 被阅读175次

需求

当用户停留超过15分钟后,用户提交订单,提示用户超时并重新加载页面

代码

data () {
    return {
        // 超时定时器
        overTimer: null,
        // 是否超时
        isOvertime: false,
    }
},
created () {
    // 开启定时器
    this.overTimer = setTimeout(() => {
      this.isOvertime = true;
    }, 900000)
},
destroyed () {
    // 销毁定时器
    clearTimeout(this.overTimer)
},
methods: {
    submitOrder () {
        // 判定是否超时
        if (this.isOvertime) {
            this.$message.error('订单已过期,请重新下单');
            window.location.reload()
        }
    }
} 

相关文章

网友评论

    本文标题:vue判断用户在页面停留时间是否超时

    本文链接:https://www.haomeiwen.com/subject/vxmkzftx.html