setTimeout 不适用于 vue.js 应用程序

发布于 2025-01-17 07:44:52 字数 1972 浏览 0 评论 0原文

我有一个函数,在页面加载后 1 秒后启动,在本地开发阶段它可以工作,但是当我构建我的应用程序并将其放在服务器上时,超时不再起作用(在 chrome 上,它仅在接受横幅后才起作用) cookies并重新加载页面),而如果我进入隐身模式,它就不起作用。

这是超时的代码:

window.setTimeout(() => {       
this.brake();     
},1000);

这是一个 vue.js 应用程序。

我试图通过插入这段代码来修改函数:

document.addEventListener('DOMContentLoaded', function() {
   window.setTimeout(() => {
      this.brake();
    },1000);
}, false);

但仍然不起作用。

测试站点的链接是: https://new.carbobrake.com/

页面完成后加载磁盘应该会自行停止,但这种情况不会发生。

----编辑----

这是我的代码:

<div id="animation-container">
      <img id="fixed-canvas-container" :src="this.homeImages[0]" alt="" />
      <img id="scroll-canvas-container" :src="this.animationImages[0]" alt="" />
      
      
      <div id="step0">
      // other code
      </div>
</div>

Javascript:

methods: {
  brake() {
        this.canvasContainer = document.getElementById("fixed-canvas-container");
        this.canvasContainer.src = this.homeImages[1];
        setTimeout(() => {
          document.body.style.overflowY = "visible";
          this.setImageMargin();
          document.getElementById("scroll-canvas-container").style.display =
            "block";

          var step0 = document.getElementById("step0");

          TweenMax.fromTo(
            step0,
            0.5,
            {
              display: "none",
              opacity: 0,
            },
            {
              display: "block",
              opacity: 1,
              ease: Power3.easeIn,
            }
          );
        }, 1100);
        // TODO check
        setTimeout(() => {
          this.canvasContainer.style.display = "none";
        },2500);

   }
 }, 
  mounted() {
  window.setTimeout(() => {
        this.brake();
      }, 1000);
  
  }

I have a function that starts up after 1 second from page loading, during the development phase locally it works, but when I build my application and put it on a server the timeout no longer works (on chrome it works only after accepting the banner of cookies and reloaded the page), while if I go in incognito mode it does not work.

This is the code of timeout:

window.setTimeout(() => {       
this.brake();     
},1000);

This is a vue.js application.

I tried to modify the function by inserting this piece of code:

document.addEventListener('DOMContentLoaded', function() {
   window.setTimeout(() => {
      this.brake();
    },1000);
}, false);

but it still doesn't work.

The link of the test site is: https://new.carbobrake.com/

Once the page has finished loading the disk should stop by itself, but this does not happen.

----EDIT----

This is my code:

<div id="animation-container">
      <img id="fixed-canvas-container" :src="this.homeImages[0]" alt="" />
      <img id="scroll-canvas-container" :src="this.animationImages[0]" alt="" />
      
      
      <div id="step0">
      // other code
      </div>
</div>

Javascript:

methods: {
  brake() {
        this.canvasContainer = document.getElementById("fixed-canvas-container");
        this.canvasContainer.src = this.homeImages[1];
        setTimeout(() => {
          document.body.style.overflowY = "visible";
          this.setImageMargin();
          document.getElementById("scroll-canvas-container").style.display =
            "block";

          var step0 = document.getElementById("step0");

          TweenMax.fromTo(
            step0,
            0.5,
            {
              display: "none",
              opacity: 0,
            },
            {
              display: "block",
              opacity: 1,
              ease: Power3.easeIn,
            }
          );
        }, 1100);
        // TODO check
        setTimeout(() => {
          this.canvasContainer.style.display = "none";
        },2500);

   }
 }, 
  mounted() {
  window.setTimeout(() => {
        this.brake();
      }, 1000);
  
  }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

简美 2025-01-24 07:44:52

我这样解决了它:

window.addEventListener('load', this.brake);

现在它在页面加载末尾正常工作。

I solved it like this:

window.addEventListener('load', this.brake);

Now it works correctly at the end of the page load.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文