乱码乱a∨中文字幕,在线免费激情视频,亚洲欧美久久夜夜潮,国产在线网址

  1. <sub id="hjl7n"></sub>

    1. <sub id="hjl7n"></sub>

      <legend id="hjl7n"></legend>

      當(dāng)前位置:首頁(yè) >  站長(zhǎng) >  編程技術(shù) >  正文

      解決js中的setInterval清空定時(shí)器不管用問題

       2020-11-19 13:59  來(lái)源: 腳本之家   我來(lái)投稿 撤稿糾錯(cuò)

        阿里云優(yōu)惠券 先領(lǐng)券再下單

      這篇文章主要介紹了解決js中的setInterval清空定時(shí)器不管用問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來(lái)看看吧

      使用場(chǎng)景:我在函數(shù)A中調(diào)用定時(shí)器函數(shù),定時(shí)器是單獨(dú)寫的一個(gè)函數(shù)

      原因: 頁(yè)面加載時(shí)我調(diào)用了1次函數(shù)A,然后又單獨(dú)調(diào)用了一次定時(shí)器函數(shù),導(dǎo)致調(diào)用了2次setInterval(),導(dǎo)致有setInterval_id有2個(gè)值。

      通過打印定時(shí)器的值發(fā)現(xiàn)的問題。

      clearInterval()只關(guān)閉了其中一個(gè)setInterval_id,另一個(gè)setInterval_id還會(huì)啟動(dòng)setInterval()。

      解決方法: 把單獨(dú)調(diào)用的定時(shí)器函數(shù)去掉。

      補(bǔ)充知識(shí): js vue中setTimeout無(wú)法通過clearTimeout清除問題

      在異步清除中,利用vue 中data存放setTimeout的標(biāo)識(shí)進(jìn)行清除時(shí),無(wú)法清除。則需要在函數(shù)前加上window.即可

      如window.setTimeout與window.clearTimeout

      具體代碼如下

      精簡(jiǎn)后的代碼。

      環(huán)境為electron-vue 渲染進(jìn)程異步獲取主進(jìn)程上html并渲染到頁(yè)面、過程中需要有l(wèi)oading的顯示。

      setTimeout 與clearTimeout 未加window時(shí),this.timeOutLoading事件總會(huì)被觸發(fā)。

      <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="設(shè)置" 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;'>加載超時(shí)</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>

      以上這篇解決js中的setInterval清空定時(shí)器不管用問題就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

      來(lái)源:腳本之家

      鏈接:https://www.jb51.net/article/199941.htm

      申請(qǐng)創(chuàng)業(yè)報(bào)道,分享創(chuàng)業(yè)好點(diǎn)子。點(diǎn)擊此處,共同探討創(chuàng)業(yè)新機(jī)遇!

      相關(guān)文章

      熱門排行

      信息推薦