vue中setTimeout无法通过clearTimeout清除问题 - Web前端
作者:98wpeu发布时间:2026-09-11分类:网页前端技术浏览:4
导读:在异步清除中,利用vue中data存放setTimeout的标识进行清除时,无法清除。则需要在函数前加上window.即可如window.settimeout与window.cl...

在异步清除中,利用vue 中data存放setTimeout的标识进行清除时,无法清除。则需要在函数前加上window.即可
如window.settimeout与window.cleartimeout
具体代码如下
精简后的代码。
环境为electron-VUE 渲染进程异步获取主进程上html并渲染到页面、过程中需要有loading的显示。
setTimeout 与clearTimeout 未加window时,this.timeOutloading事件总会被触发。
<template>
<div id="dev">
<el-tabs v-model="activeName" @TAB-click="handleClick" v-loading="loading">
<el-tab-pane label="文档" name="first">
<div v-HTML="html"></div>
</el-tab-pane>
<el-tab-pane label="设置" name="second">
<v-devCard></v-devCard>
</el-tab-pane>
</el-tabs>
</div>
</template>
<script>
const {iPCRenderer:ipc} = reqUIre('electron');
Export default {
data(){
return{
activeName: 'second',
html:'',
loading:false,
timeOutLoading:0
}
},
methods:{
handleClick(tab, event) {
if(tab.name == 'first' && this.loading == false){
if(this.timeOutLoading != 0){
window.clearTimeout(this.timeOutLoading);
}
this.html = "<div style='text-align:center; height:200px; line-height:200px;'>加载中...</div>";
this.loading = true;
this.timeOutLoading = window.setTimeout(() => {
if(this.loading == true){
this.loading = false;
this.html = "<div style='text-align:center; height:200px; line-height:200px;'>加载超时</div>";
}
}, 3000);
window.setTimeout(() => {
ipc.send("getPage");
}, 500);
}
}
},
mounted(){
ipc.on('getPage-reply', (event, arg) => {
if(this.timeOutLoading != 0){
window.clearTimeout(this.timeOutLoading);
this.timeOutLoading = 0;
}
this.loading = false;
this.html = arg;
});
}
}
</script>
相关推荐
- Python正则表达式匹配多行注释和文档字符串 - Web前端
- Windows Terminal:完整指南 - Web前端
- 微信小程序开发:随机生成验证码 - Web前端
- 了解下经过重构后的Microsoft Edge浏览器 - Web前端
- Adobe杀死Acrobat和Reader中的Flash –推出了这些重要的安全错误修复程序 - Web前端
- 聊聊前端开发中Vue.js组件间的循环引用方法 - Web前端
- Windows 10 20H2更新:面向IT专业人员的新功能 - Web前端
- 在vscode里开发vue项目需要安装的插件:eslint - Web前端
- Twitter、YouTube、Facebook等知名网站已经开始强制限制IE了,您还在用IE? - Web前端
- 如何从DOM转换为SVG坐标并再次返回 - Web前端
- 网页前端技术排行
-
- 1[Web前端]用javascript实现默认图片替代未显示的图片 - Web前端
- 2分析Iconfont-阿里巴巴矢量常用图标库 - Web前端
- 3jQuery实例教程:制作网页中可折叠的面板 - Web前端
- 4【第六章】Foundation之按钮和下拉功能 - Web前端
- 5基于jquery的滚动条滚动固定div(附演示下载) - Web前端
- 6jQuery编写widget的一些技巧分享 - Web前端
- 7分享精心挑选的12款优秀jQuery Ajax分页插件和教程 - Web前端
- 8jQuery实现鼠标移到元素上动态提示消息框效果 - Web前端
- 9在Mac/PC上远程调试iPhone/iPad上的网页 - Web前端
- 最近发表
-
- WordPress随机显示特色图片插件:Random Post Thumbnails
- KeePass实现Chrome浏览器自动填充密码方法一
- LNMP一键包nginx 301强制跳转到https教程
- KeePass实现Chrome浏览器自动填充密码方法二
- #建站# 免费的VPS管理软件Xshell8/Xftp8中文版下载
- 使用Xshell 8连接VPS教程_电脑登录vps的方法
- WordPress评论界面添加烟花????效果
- 不同浏览器书签同步方案:坚果云+Floccus_详细使用教程
- iOS端KeePassXC客户端APP:Strongbox Password Safe
- 给WordPress评论中的Gravatar头像图片添加ALT属性


