css中的v-bind 动态变化

v-bind()<style> 中是 CSS 与组件数据的桥梁 ,可以让你写响应式 CSS,而不需要通过 :style 或类切换来手动更新样式。

javascript 复制代码
<script lang="ts" setup>
const testBindCssVariable = ref('#ff6700')
function changeTestBindCssVariable() {
  if (testBindCssVariable.value === '#ff6700') {
    testBindCssVariable.value = '#67ff00'
  }
  else {
    testBindCssVariable.value = '#ff6700'
  }
}
</script>

<template>
  <button class="mt-4 w-60 text-center" @click="changeTestBindCssVariable">
    toggle v-bind css变量
  </button>
  <view class="test-css my-2 text-center">
    测试v-bind css变量的具体文案
  </view>
</template>

<style lang="scss" scoped>
.test-css {
  color: v-bind(testBindCssVariable);
  font-size: 24px;
}
</style>
相关推荐
JarvanMo12 分钟前
8 个你可能忽略了的 Flutter 小部件(一)
前端
JarvanMo20 分钟前
Flutter 中的微服务架构:拆解你的应用
前端
JarvanMo21 分钟前
对我来说,那个框架就是 Flutter。
前端
Mintopia29 分钟前
🧠 自监督学习在 WebAIGC 中的技术突破与应用前景
前端·人工智能·aigc
Mintopia31 分钟前
🧭 传统 Web 开发最好的 AI 助手框架排行榜(2025版)
前端·人工智能·aigc
坚持就完事了41 分钟前
003-HTML之表单
服务器·前端·html
晓得迷路了1 小时前
栗子前端技术周刊第 105 期 - npm 安全性加强、Storybook 10、htmx 4.0 Alpha 1...
前端·javascript·npm
七号练习生.c1 小时前
CSS入门
前端·css·tensorflow
程序员爱钓鱼1 小时前
Python编程实战——Python实用工具与库:Matplotlib数据可视化
前端·后端·python