1. Define variables in js:
<script setup>
import {computed, ref} from "vue";
const fileWidth = ref(150);
const cssVars = computed(() => {
return (fileWidth.value - 10) + 'px'
});
</script>
2. Use variables in js in SCSS:
//直接使用
<style lang="scss" scoped>
.pendingImg {
width: v-bind(cssVars);
}
</style>
//在scss中定义变量后再使用
<style lang="scss" scoped>
$baseWidth: v-bind(cssVars);
.pendingImg {
width: $baseWidth;
}
</style>