SCSS の JS での変数の使用

1. js で変数を定義します。

<script setup>
import {computed, ref} from "vue";

const fileWidth = ref(150);
const cssVars = computed(() => {
    return (fileWidth.value - 10) + 'px'
});
</script>

2. SCSS の js で変数を使用します。

//直接使用
<style lang="scss" scoped>
.pendingImg {
  width: v-bind(cssVars);
}
</style>


//在scss中定义变量后再使用
<style lang="scss" scoped>
$baseWidth: v-bind(cssVars);
.pendingImg {
  width: $baseWidth;
}
</style>

おすすめ

転載: blog.csdn.net/weixin_57092157/article/details/130237254