vue3中css使用script中定义的变量

代码

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>

效果

相关推荐
疯狂的魔鬼9 小时前
精确计算容器剩余视口高度:useAutoContainerFullHeight 的工程实践
前端·css·typescript
用户059540174469 小时前
用了 3 个月 ChatGPT,才发现它一直在遗忘——用 Playwright 自动化验证记忆存储一致性
前端·css
spmcor9 小时前
CSS 黏性定位完全指南:从入门到精通
css
用户059540174469 小时前
用了半年 LangChain Memory,才发现回滚测试压根没测对
前端·css
丨我是张先生丨1 天前
日语单词 Web Page
前端·css·css3
吃西瓜不吐籽_1 天前
2026 届前端校招冲刺:2 万字高频面试题库(含详解、追问与评分标准)
前端·javascript·css·typescript·前端框架·es6
Csvn2 天前
CSS :has() 选择器实战:没有它之前我们写了多少冗余 JS
前端·css
用户059540174463 天前
大模型长上下文遗忘排查实录:用 Playwright 自动化测试,揪出了 90% 的存储序列化 bug
前端·css
天蓝色的鱼鱼4 天前
关于 CSS 你可能不知道的属性,但关键时刻很有用
前端·css
用户059540174464 天前
向量库静默丢数据踩坑实录:Playwright 端到端测试让我排查了72小时
前端·css