无法在 $refs 属性中添加样式。无法设置未定义的属性“cssText”。这可能吗?找不到任何类似的
this.$refs['ticketCode_'+this.resoTrans_id].style.cssText =
"background-color:#66BB6A !important; border:1px solid #66BB6A !important; color:#fff !important;";
在没有 .style 的情况下打印出来似乎工作正常 console.log(this.$refs['ticketCode_'+this.resoTrans_id])
VueComponent {_uid: 493, _isVue: true, $options:
最佳答案
你不应该使用 cssText 而是使用 JavaScript API 来设置样式(你也可以在 $refs 上做):
let $ref = this.$refs['ticketCode_' + this.resoTrans_id]
$ref.style.backgroundColor = '#66bb6a';
$ref.style.border = '1px solid #66bb6a';
...
更好的方法是直接在模板中利用 Vue 的强大功能:
<your-element ref="'ticketCode_' + resoTrans_id" :style="{ backgroundColor: '#66bb6a', border: '1px solid #66bb6a' /* ... */ }" />
关于javascript - 在 $refs 中添加样式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49572850/