Home >Web Front-end >Vue.js >How to change the style in vue.js
Vue.js method to change the style: first define the ref attribute for the element; then modify the element's style through the js method, the code is ['background-color:#1F2429;width:66px']; finally modify the single You can use the style name directly when creating a style.
The operating environment of this tutorial: windows7 system, vue version 2.9.6. This method is suitable for all brands of computers.
[Related article recommendations: vue.js]
How to change the style in vue.js:
1. Element definition ref attribute
<el-button ref="btnClick" class="list_button" " @click="openClose"></el-button>
2. Modify the style of the element through js method. When modifying multiple styles, you can use 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. When modifying a single style, you can directly use the style name
function openClose() { this.isCollapse = !this.isCollapse if (this.isCollapse) { this.$refs.btnClick.$el.style.color = 'red'; } else { this.$refs.btnClick.$el.style.color = 'blue'; } }
Related learning recommendations: javascript learning tutorial
The above is the detailed content of How to change the style in vue.js. For more information, please follow other related articles on the PHP Chinese website!