代码
javascript
<template>
<div class="box">haha</div>
</template>
<script setup lang="ts">
const boxWidth = '500px'
</script>
<style lang="scss">
.box {
width: v-bind(boxWidth);
height: 200px;
background-color: red;
}
</style>
效果
![](https://file.jishuzhan.net/article/1701465353646772226/bb5a953c57054f5591ea285706789512.png)