Home >Web Front-end >Vue.js >How to change the style in vue.js

How to change the style in vue.js

coldplay.xixi
coldplay.xixiOriginal
2020-11-25 14:01:294372browse

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.

How to change the style in vue.js

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

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 = &#39;red&#39;;
           
        } else {
            this.$refs.btnClick.$el.style.color = &#39;blue&#39;;
        }
    }

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn