vue.js怎么修改样式

本文环境:windows7、vue2.9.6,该方法适用于所有品牌的电脑。

vue.js修改样式的方法:

1、给元素定义ref 属性

 <el-button ref="btnClick" class="list_button" " @click="openClose"></el-button>

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怎么修改样式的详细内容,更多请关注0133技术站其它相关文章!

赞(0) 打赏
未经允许不得转载:0133技术站首页 » Vue.js 答疑