vue.js怎麼改變樣式

2020-11-25 15:01:24

vue.js改變樣式的方法:首先給元素定義ref屬性;然後通過js方法修改元素的樣式,程式碼為【'background-color:#1F2429;width:66px'】;最後修改單一樣式時可直接使用樣式名稱。

【相關文章推薦:】

  • 該方法適用於所有品牌電腦

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怎麼改變樣式的詳細內容,更多請關注TW511.COM其它相關文章!