<template>
<div class="box" :style="styleVar">
</div>
</template>
<script>
export default {
props: {
height: {
type: Number,
default: 54,
},
},
computed: {
styleVar() {
return {
'--box-height': this.height + 'px'
}
}
},
}
</script>
<style scoped>
.box {
height: var(--box-height);
}
</style>
css 变量注入
最新推荐文章于 2023-11-12 12:04:23 发布
这是一个关于Vue.js的博客,展示了如何在组件中通过props接收外部传入的高度值,并使用计算属性动态设置CSS变量来改变组件的高度。内容涉及到CSS变量、组件props和计算属性的使用。

2516

被折叠的 条评论
为什么被折叠?



