setTimeout 不适用于 vue.js 应用程序
我有一个函数,在页面加载后 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我这样解决了它:
现在它在页面加载末尾正常工作。
I solved it like this:
Now it works correctly at the end of the page load.