Skip to content

14 - 动态CSS-模板中的写法 (Dynamic CSS- Writing in templates) #2803

@Tofu-Xx

Description

@Tofu-Xx
<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>

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions