通过动态绑定style,声明css变量"--bgColor",把变量”color”赋给“--bgColor”

  <div ref="chart-circle" class="chart-circle" :style="{ '--bgColor': color }"></div>

在css中使用 var函数 读取“--bgColor”变量

.chart-circle {
  width: 80px;
  height: 80px;
  position: relative;
  &::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background-color: var(--bgColor);
  }
}

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐