铆钉 |如何将图像 link 绑定到样式="background-image:url()"
Rivetjs | How to bind image link to style="background-image:url()"
如何将 item.image 绑定到 style="background-image:url()"
<div rv-each-item="items">
<div style="background-image:url()"></div>
</div>
单向活页夹
rivets.binders.color = function(el, value) {
el.style.color = value
}
<button rv-color="label.color">Apply</button>
我解决了这个问题
<div rv-each-item="items">
<div rv-view-style="item.image"></div>
</div>
**JS**
rivets.binders['view-style'] = function(el, value) {
el.style = 'background-image:url(https://xxx/' + value + ')';
}
如何将 item.image 绑定到 style="background-image:url()"
<div rv-each-item="items">
<div style="background-image:url()"></div>
</div>
单向活页夹
rivets.binders.color = function(el, value) {
el.style.color = value
}
<button rv-color="label.color">Apply</button>
我解决了这个问题
<div rv-each-item="items">
<div rv-view-style="item.image"></div>
</div>
**JS**
rivets.binders['view-style'] = function(el, value) {
el.style = 'background-image:url(https://xxx/' + value + ')';
}