查看: 8601|回复: 6

vue组件添加定时器,刷新之后定时器还存在

升级   6.48%

44

主题

46

回帖

648

积分

注册会员

Rank: 2

积分
648
发表于 2023-6-28 16:19:40 | 显示全部楼层 |阅读模式
vue组件添加定时器,点顶部这个刷新按钮刷新,刷新之后定时器逻辑还存在,而且清除不了

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

升级   100%

139

主题

1万

回帖

4万

积分

超级版主

Rank: 8Rank: 8

积分
41458
发表于 2023-6-29 10:20:21 | 显示全部楼层
什么样的定时器,怎么写的?
回复

使用道具 举报

升级   6.48%

44

主题

46

回帖

648

积分

注册会员

Rank: 2

积分
648
发表于 2023-6-29 11:12:12 | 显示全部楼层
论坛管理员 发表于 2023-6-29 10:20
什么样的定时器,怎么写的?

this.timer = setTimeout(() => {
         //执行的函数
console.log('每隔2s执行一次')
        }, 2000);
执行之后,顶上出来的刷新图标,点击之后,定时器一直在执行,除非用浏览器自带的刷新才能清除
回复

使用道具 举报

升级   100%

139

主题

1万

回帖

4万

积分

超级版主

Rank: 8Rank: 8

积分
41458
发表于 2023-6-29 16:39:58 | 显示全部楼层
你执行的方法里写的什么?只是console.log吗,这里看不出来您用了vue组件呢,你这段脚本具体写在哪里?
回复

使用道具 举报

升级   6.48%

44

主题

46

回帖

648

积分

注册会员

Rank: 2

积分
648
发表于 2023-6-29 16:50:01 | 显示全部楼层
论坛管理员 发表于 2023-6-29 16:39
你执行的方法里写的什么?只是console.log吗,这里看不出来您用了vue组件呢,你这段脚本具体写在哪里?
...

在methods里面添加的函数
getDeviceSlave(data) {
  let that = this;
  this.timer = setTimeout(() => {
    //执行的函数
    getDeviceSlave(data).then(
        res => {
          console.log(res)
          if (res.status === 200) {
            // that.drawer = false;
            if (res.data.length) {
              that.getDataByTemplate(res.data[0])
            }
            that.currentData = res.data.data;
          }
        }
    ).catch(
        err => {
          that.$message.error(err.msg);
        }
    );
  }, 2000);
},
回复

使用道具 举报

升级   100%

139

主题

1万

回帖

4万

积分

超级版主

Rank: 8Rank: 8

积分
41458
发表于 2023-6-30 09:20:32 | 显示全部楼层
完整的配置发来看一下,什么样的表单,什么控件,里面都做了什么配置,或者您直接这个表单导出来,管理员这边检查一下也可以
回复

使用道具 举报

升级   6.48%

44

主题

46

回帖

648

积分

注册会员

Rank: 2

积分
648
发表于 2023-6-30 10:34:11 | 显示全部楼层
论坛管理员 发表于 2023-6-30 09:20
完整的配置发来看一下,什么样的表单,什么控件,里面都做了什么配置,或者您直接这个表单导出来,管理员这 ...

<template>
  <div class="o2task">

    <h3>{{lp.taskListTitle}}</h3>
    <br>
    <table align="center" class="taskListTable" border="1">
      <tr>
        <th>{{lp.taskTitle}}</th>
        <th>{{lp.taskProcess}}</th>
        <th>{{lp.taskTime}}</th>
      </tr>
      <tr v-for="task in taskList">
        <td><a href="#" @click="openTask(task.work)">{{task.title}}</a></td>
        <td>{{task.processName}}</td>
        <td>{{task.startTime}}</td>
      </tr>
    </table>
    <br>
    <button @click="openCalendar">{{lp.openCalendar}}</button>
    <button @click="openOrganization">{{lp.openOrganization}}</button>
    <button @click="startProcess">{{lp.startProcess}}</button>
    <button @click="createDocument">{{lp.createDocument}}</button>
    <br>
    <button @click="openInBrowser">{{lp.openInBrowser}}</button>
  </div>
</template>

<script>
import {o2, lp, component} from '@o2oa/component';

export default {
  name: 'O2Task',
  data(){
    return {
      taskList: [],
      lp: lp,
      index: 1,
      timer: ''
    }
  },
  created(){
    o2.Actions.load("x_processplatform_assemble_surface").TaskAction.V2ListPaging(1, 5).then((json)=>{
      this.taskList = json.data;
    });
  },
  methods: {
    openTask(id){
      o2.api.page.openWork(id);
    },
    openCalendar(){
      // o2.api.page.openApplication("Calendar");
      let that = this;
      that.timer = setInterval(function() {
        that.index++;
        console.log(that.index)
      },1000);
    },
    openOrganization(){
      o2.api.page.openApplication("Org");
    },
    openInBrowser() {
      component.openInNewBrowser(true);
    },
    startProcess(){
      o2.api.page.startProcess();
    },
    createDocument(){
      o2.api.page.createDocument();
    }
  }
}
</script>

<style scoped>
.taskListTable{
  width: 800px;
  box-sizing: border-box;
  border-collapse: collapse;
}
.taskListTable th{
  height: 30px;
  line-height: 30px;
  background-color: #d4e6fb;
}
.taskListTable td{
  height: 24px;
  line-height: 24px;
}
button {
  cursor: pointer;
  font-size: 12px;
  margin: 10px;
  padding: 5px 10px;
  color: #ffffff;
  background-color: #4a90e2;
  border: 1px solid #4a90e2;
  border-radius: 100px;
}
h3 {
  margin: 40px 0 0;
}
a {
  color: #4a90e2;
}
</style>
点击 打开日程管理 按钮后,再点上方刷新按钮,控制台还会一直在打印
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

联系客服 关注微信 下载APP 返回顶部 返回列表
viewthread