vue3在style中使用data定义的变量

在style标签中使用v-bind绑定相应的变量

<template>
  <div class="text">hello</div>
</template>

<script>
  export default {
    data() {
      return {
        color: 'red',
        font: {
          size: '2em'
        }
      }
    }
</script>

<style>
  .text {
    color: v-bind(color);

    /* expressions (wrap in quotes) */
    font-size: v-bind('font.size');
  }
</style>

参考:https://github.com/vuejs/rfcs/pull/231

猜你喜欢

转载自blog.csdn.net/qq_41839808/article/details/129243246