xingkongshensui 发表于 2023-6-28 16:19:40

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

vue组件添加定时器,点顶部这个刷新按钮刷新,刷新之后定时器逻辑还存在,而且清除不了

论坛管理员 发表于 2023-6-29 10:20:21

什么样的定时器,怎么写的?

xingkongshensui 发表于 2023-6-29 11:12:12

论坛管理员 发表于 2023-6-29 10:20
什么样的定时器,怎么写的?

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

论坛管理员 发表于 2023-6-29 16:39:58

你执行的方法里写的什么?只是console.log吗,这里看不出来您用了vue组件呢,你这段脚本具体写在哪里?

xingkongshensui 发表于 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)
            }
            that.currentData = res.data.data;
          }
      }
    ).catch(
      err => {
          that.$message.error(err.msg);
      }
    );
}, 2000);
},

论坛管理员 发表于 2023-6-30 09:20:32

完整的配置发来看一下,什么样的表单,什么控件,里面都做了什么配置,或者您直接这个表单导出来,管理员这边检查一下也可以

xingkongshensui 发表于 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>
点击 打开日程管理 按钮后,再点上方刷新按钮,控制台还会一直在打印
页: [1]
查看完整版本: vue组件添加定时器,刷新之后定时器还存在