【问题标题】:Is it possible to use curly braces in vue js style segment?是否可以在 vue js 样式段中使用花括号?
【发布时间】:2021-12-16 10:02:32
【问题描述】:

我想知道是否可以在 vue.js 的样式段中使用花括号作为值?

例如

.container {
  background: url({{ image-url }};
  color: {{ color-1 }}
}

【问题讨论】:

    标签: javascript css vue.js vuejs3


    【解决方案1】:

    有一个experimental feature 用于绑定脚本提供的 CSS 变量。试试这个:

    <template>
      <div class="text">Lorem ipsum</div>
    </template>
    
    <script>
    import {ref} from 'vue'
    export default {
      setup() {
        const color = ref('red');
        const image = ref('url(https://picsum.photos/200/300)');
        
        return {color}
      }
    };
    </script>
    
    <style vars="{ color, image }">
    .text {
      color: var(--color);
      background-image: var(--image);
    }
    </style>
    

    或尝试新的v-bind() 注入

    【讨论】:

    猜你喜欢
    • 2021-10-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-26
    相关资源
    最近更新 更多