小工具知识网

当前位置: 首页 > 行业知识 > 前端-VUE2中的动态CSS样式

行业知识

前端-VUE2中的动态CSS样式

2026-11-04 11:51:43 来源:互联网转载

一、第一种,:style写法,分为直接赋值变量,或者使用CSS样式对象

1.赋值变量

点击

 computed: {

    buttonStyle() {

      return {

        backgroundColindex.php/tags-1038.html" >or: this.clicked ? 'green' : 'blue',

        color: 'white',

        padding: '10px 20px'

      };

    }

  }

2.使用CSS样式对象

111

export default {

  data() {

    return {

      bgColor: 'yellow',

      textColor: 'blue'

    };

  }

};

二、第二种,使用类名绑定:class

  111

 

export default {

  data() {

    return {

      isActive: false,

      isLargeText: true

    };

  }

};

 

.highlight {

  background-color: yellow;

}

 

.large-text {

  font-size: 20px;

}

上一篇:VScode 安装中文插件,不生效的解决办法

下一篇:查理怎么卡技能?