【发布时间】:2021-11-03 17:47:22
【问题描述】:
如何在<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>
【问题讨论】: