0
我想通过添加一类.lightTheme
来使用css转换属性来将#app
背景从黑色变为淡色。 .lightTheme
类的添加按预期工作,但转换不会。我需要添加Vue transition element吗?如果是的话如何? #app
是不会离开/进入DOM - !我只是想制作动画的属性(我不希望尽可能地增加不必要的代码Vue.js css过渡类更改
HTML
<div id="app" v-bind:class="{ lightTheme: isActive }">
<button v-on:click="toggleTheme">Change theme</button>
</div>
JS
new Vue({
el: '#app',
data: {
isActive: false
},
methods: {
toggleTheme: function(){
this.isActive = !this.isActive;
// some code to filter users
}
}
});
CSS
#app {
background: black;
transition: 1s;
}
#app.lightTheme {
background: white;
}
谢谢!