Usando variables en JS en SCSS

1. Definir variables en js:

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

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

2. Use variables en js en SCSS:

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


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

Supongo que te gusta

Origin blog.csdn.net/weixin_57092157/article/details/130237254
Recomendado
Clasificación