Home > Web Front-end > Vue.js > body text

How to change the style in vue.js

coldplay.xixi
Release: 2020-11-30 15:39:08
Original
4228 people have browsed it

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

 
Copy after login

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';
        }
    }
Copy after login

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';
        }
    }
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!