动态 CSS

291 阅读1分钟
<script setup lang="ts">
import { ref } from 'vue'
const props = defineProps(['color'])
const color = ref('blue')
const style = ref({
  width: '200px',
  height: '200px',
})
</script>

<template>
  <div class="son"></div>
</template>

<style lang="scss" scoped>
.son {
  color: v-bind(color);
  width: v-bind('style.width');
  height: v-bind('style.height');
  background-color: red;
}
</style>