如何在 <style>..</style>
中使用 data()
的数值?我尝试了多种组合(带/不带 this
,带/不带 {{brackets}}
等),但无法使其工作。然而,如果我输入像 '#f00'
这样的值,它就能正常工作。
我建立了一个这样的模板:
<template>
<ul class="striped">
<li>foo</li>
<li>bar</li>
<li>foobar</li>
</ul>
</template>
<style>
ul.striped> li:nth-of-type(odd) {
background-color: this.colors[0].backgroundcolor; //dynamic value from data()
}
</style>
<script>
data() {
return {
colors: [{'backgroundcolor':'#def'}], //simplified version for explanation
[..]
</script>