将对象数据传递给 Vue.js 中的样式 [英] Pass object data to styles in Vue.js

查看:18
本文介绍了将对象数据传递给 Vue.js 中的样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够在单个文件组件中将数据从对象传递到 .但是,这似乎不太可能.

I want to be able to pass data from a object to the <styles> in a single file component. However, it doesn't seem like this is possible.

我正在努力实现的目标:

What I'm trying to achieve:

<template></template>

<script>
export default {
    data: function() {
        return { color: "#f00" }
    }
}
</script>

<style>
body {
    background-color: this.color
}
</style>

推荐答案

据我所知,您无法将数据从组件传递到其样式表.

As far as I'm aware, you are not able to pass data from the component to its stylesheets.

就动态样式而言,最佳做法是在需要时使用 v-bind:classv-bind:style.