简体   繁体   English

aurelia中的javascript settimeout函数

[英]javascript settimeout function in aurelia

I want to hide an element after some time ( about 2 seconds ). 我想在一段时间后(大约2秒钟)隐藏一个元素。 in javascript in can use setTimeout function for that. 在javascript中可以使用setTimeout函数。 Is there a way that I could use it on Aurelia? 有没有办法可以在Aurelia上使用它? or is there a better way for this? 还是有更好的方法吗?

You can hide the element using the if custom attribute included in Aurelia. 您可以使用Aurelia中包含的if custom属性隐藏元素。 Then bind that to a property on the viewmodel. 然后将其绑定到viewmodel上的属性。

this.showItem = true;
window.setTimeout(() => this.showItem = false, 2000);
<h1 if.bind="showItem">I will hide in 2 seconds</h1>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM