Javascript 延迟更改样式

Javascript 延迟更改样式,javascript,html,css,vue.js,vuejs2,Javascript,Html,Css,Vue.js,Vuejs2,我想在单击按钮后延迟切换div的样式 如果我简单地使用类似于this.customEffect='blueorder'的东西,代码就会很好地工作无超时 newvue({ el:“#应用程序”, 数据:{ 自定义效果:“” }, 方法:{ 开始:函数(){ setTimeout(函数(){ this.customEffect='blueorder'; }, 1000); setTimeout(函数(){ this.customEffect='redtext'; }, 2000); } } });

我想在单击按钮后延迟切换div的样式

如果我简单地使用类似于
this.customEffect='blueorder'的东西,代码就会很好地工作无超时

newvue({
el:“#应用程序”,
数据:{
自定义效果:“”
},
方法:{
开始:函数(){
setTimeout(函数(){
this.customEffect='blueorder';
}, 1000);
setTimeout(函数(){
this.customEffect='redtext';
}, 2000);
}
}
});
.blueorder{
边框:3件纯蓝;
}
.redtext{
颜色:红色;
}

开始
一些文本

我认为您遇到的问题是超时中的
上下文是匿名函数的,而不是父对象。可以使用箭头函数或显式绑定

newvue({
el:“#应用程序”,
数据:{
自定义效果:“”
},
方法:{
开始:函数(){
setTimeout((函数(){//BIND
this.customEffect='blueorder';
}).绑定(本),1000);
setTimeout(()=>{//OR=>
this.customEffect='redtext';
}, 2000);
}
}
});
.blueorder{
边框:3件纯蓝;
}
.redtext{
颜色:红色;
}

开始
一些文本

我认为您遇到的问题是超时中的
上下文是匿名函数的,而不是父对象。可以使用箭头函数或显式绑定

newvue({
el:“#应用程序”,
数据:{
自定义效果:“”
},
方法:{
开始:函数(){
setTimeout((函数(){//BIND
this.customEffect='blueorder';
}).绑定(本),1000);
setTimeout(()=>{//OR=>
this.customEffect='redtext';
}, 2000);
}
}
});
.blueorder{
边框:3件纯蓝;
}
.redtext{
颜色:红色;
}

开始
一些文本

您可以使用boostrap来避免生成已经具有boostrap功能的代码

或者,您可以创建自己的css类:

例如:

.animated {
-webkit-animation-duration: 1s;
animation-duration: 1s;
-webkit-animation-fill-mode: both;
animation-fill-mode: both;
}

.fast {
-webkit-animation-duration: 0.4s;
animation-duration: 0.4s;
-webkit-animation-fill-mode: both;
animation-fill-mode: both;
}

@keyframes fadeIn {
from {
  opacity: 0;
}

to {
  opacity: 1;
}
}

.fadeIn {
animation-name: fadeIn;
html示例:

<div class="animated fadeIn fast">
  <h1 class="display-4">My app</h1>
  <p class="lead">This is a great app!</p>
<div>

我的应用程序

这是一个很棒的应用程序


您可以使用boostrap来避免生成已经具有boostrap功能的代码

或者,您可以创建自己的css类:

例如:

.animated {
-webkit-animation-duration: 1s;
animation-duration: 1s;
-webkit-animation-fill-mode: both;
animation-fill-mode: both;
}

.fast {
-webkit-animation-duration: 0.4s;
animation-duration: 0.4s;
-webkit-animation-fill-mode: both;
animation-fill-mode: both;
}

@keyframes fadeIn {
from {
  opacity: 0;
}

to {
  opacity: 1;
}
}

.fadeIn {
animation-name: fadeIn;
html示例:

<div class="animated fadeIn fast">
  <h1 class="display-4">My app</h1>
  <p class="lead">This is a great app!</p>
<div>

我的应用程序

这是一个很棒的应用程序


您可以使用lodash的去盎司方法。


在需要导入lodash之前,您可以使用lodash的去盎司方法。


在您需要导入lodash之前

谢谢,Daniel,但我正在尝试学习Vue,因此使用其他LIB不是我一直在搜索的内容谢谢,Daniel,但我正在尝试学习Vue,因此使用其他LIB不是我一直在搜索的内容