简单代码示例:
<script setup lang="ts">
interface IProps {
height?: number;
}
// 默认props赋值
const props = withDefaults(defineProps<IProps>(), {
height: 40,
})
const heightPx = `${props.height}px`
</script>
<template>
<div class="home">
home-1
</div>
</template>
<style lang="scss">
.home {
height: v-bind(heightPx);
}
</style>
1.在<script>标签定义xx变量
2.在<style lang="scss">使用:
v-bind(xx);