这篇文章主要介绍vue.js改变样式的方法,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!

vue.js改变样式的方法:首先给元素定义ref属性;然后通过js方法修改元素的样式,代码为【'background-color:#1F2429;width:66px'】;最后修改单一样式时可直接使用样式名称。
vue.js改变样式的方法:
1、给元素定义ref属性
2、通过js 方法修改元素的样式 修改较多样式时可使用cssText
function openClose() {
this.isCollapse = !this.isCollapse
if (this.isCollapse) {
this.$refs.btnClick.$el.style.cssText =
'background-color:#1F2429;width:66px';
} else {
this.$refs.btnClick.$el.style.cssText =
'background-color:#1F2429;width:140px';
}
}3、修改单一样式时可直接使用样式名称
function openClose() {
this.isCollapse = !this.isCollapse
if (this.isCollapse) {
this.$refs.btnClick.$el.style.color = 'red';
} else {
this.$refs.btnClick.$el.style.color = 'blue';
}
}以上是“vue.js改变样式的方法”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注创新互联行业资讯频道!