在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>

 

posted @ 2024-03-05 10:40  磊~~  阅读(51)  评论(0编辑  收藏  举报