首頁  >  文章  >  web前端  >  vue.js怎麼改變樣式

vue.js怎麼改變樣式

coldplay.xixi
coldplay.xixi原創
2020-11-25 14:01:294307瀏覽

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

vue.js怎麼改變樣式

本教學操作環境:windows7系統、vue2.9.6版,此方法適用於所有品牌電腦。

【相關文章推薦:vue.js

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 =
                &#39;background-color:#1F2429;width:66px&#39;;
           
        } else {
            this.$refs.btnClick.$el.style.cssText =
                &#39;background-color:#1F2429;width:140px&#39;;
        }
    }

3、修改單一樣式時可直接使用樣式名稱

function openClose() {
        this.isCollapse = !this.isCollapse
 
        if (this.isCollapse) {
            this.$refs.btnClick.$el.style.color = &#39;red&#39;;
           
        } else {
            this.$refs.btnClick.$el.style.color = &#39;blue&#39;;
        }
    }

相關學習推薦:javascript學習教學

#

以上是vue.js怎麼改變樣式的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn