🛠️

19302 工具站

在线工具集合

文章/vue3在css中使用js中变量(v-bind() in CSS)

vue3在css中使用js中变量(v-bind() in CSS)

2022年06月12日3,647 次阅读⏱ 约 1 分钟Vue3

曾几何时,有么有过被不能用js来控制css中的变量属性而困惑,你可能说直接获取dom获取,是不是不太人性

vue3.2中引入了 style v-bind 可以实现以上的功能

<template>
  <div class="text">hello</div>
</template>
<script setup>
  import { reactive, ref } from 'vue'
  const state = reactive({
    blue: 'blue'
  })
  const red = ref('red')
</script>
<style>
  .text {
    color: v-bind(state.blue);
    background: v-bind(red);
  }
</style>

预览效果

💬评论(0)

💭

暂无评论