在vue中实现了在样式里使用js变量的方法
<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>