Skip to content

动态CSS 简单 #CSS Features

By webfansplz @webfansplz

接受挑战    接受挑战(通过单元测试)    English

Vue单文件组件 <style> 模块支持给CSS绑定动态值。

你知道它是什么吗 ? 让我们试试👇:

<script setup>
import { ref } from "vue"
const theme = ref("red")

const colors = ["blue", "yellow", "red", "green"]

setInterval(() => {
  theme.value = colors[Math.floor(Math.random() * 4)]
}, 1000)

</script>

<template>
  <p>hello</p>
</template>

<style scoped>
/* 修改以下代码绑定动态颜色 */
p {
  color: red
}
</style>

分享你的解答 查看解答