vue.js改變樣式的方法:首先給元素定義ref屬性;然后通過js方法修改元素的樣式,代碼為【'background-color:#1F2429;width:66px'】;最后修改單一樣式時可直接使用樣式名稱。
【相關文章推薦: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 = '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'; } }
相關學習推薦:javascript學習教程