相关文章推荐
魁梧的水煮鱼  ·  java fastJson ...·  3 月前    · 
坏坏的灌汤包  ·  /bin/sh: ...·  5 月前    · 
读研的酱肘子  ·  如何在Android ...·  1 年前    · 
<template>
  <div id="app" :style="{'--theme-color': themeColor}">
    <button @click="changeColor">Change Color</button>
  </div>
</template>
<script>
export default {
  data() {
    return {
      themeColor: 'blue'
  methods: {
    changeColor() {
      this.themeColor = 'red';
</script>
<style>
#app {
  --theme-color: blue;
  background-color: var(--theme-color);
</style>

这里的themeColor是一个数据属性,可以通过点击按钮进行修改。绑定到根元素的style中的--theme-color是一个CSS变量,它的值就是themeColor的值。

  •