vue.js改變樣式的方法:首先給元素定義ref屬性;然后通過(guò)js方法修改元素的樣式,代碼為【'background-color:#1F2429;width:66px'】;最后修改單一樣式時(shí)可直接使用樣式名稱(chēng)。
【相關(guān)文章推薦:vue.js】
-
該方法適用于所有品牌電腦
vue.js改變樣式的方法:
1、給元素定義ref屬性
<el-button ref="btnClick" class="list_button" " @click="openClose"></el-button>
2、通過(guò)js 方法修改元素的樣式 修改較多樣式時(shí)可使用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、修改單一樣式時(shí)可直接使用樣式名稱(chēng)
function openClose() { this.isCollapse = !this.isCollapse if (this.isCollapse) { this.$refs.btnClick.$el.style.color = 'red'; } else { this.$refs.btnClick.$el.style.color = 'blue'; } }
相關(guān)學(xué)習(xí)推薦:javascript學(xué)習(xí)教程