webfansplz / vuejs-challenges

Collection of Vue.js challenges
https://vuejs-challenges.netlify.app/
MIT License
2.71k stars 187 forks source link

14 - 动态CSS-模板写法(Dynamic CSS- template writing) #2804

Open Tofu-Xx opened 1 month ago

Tofu-Xx commented 1 month ago
<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 :style="`color:${theme}`">hello</p>
</template>