1、普通元素:
:style="{ background: `url(${picture})`, 'background-size': '100% 100%' }"
注:picture是个变量,里面返回图片的路径。如:
picture:require('../../assets/images/login.png')
也可以是个函数,根据传参动态的返回图片路径:
picture(item){
if(item==='case1'){
return require('../../assets/images/case1.png')
}
else{
return require('../../assets/images/case2.png')
}
}
2.直接拼凑
根据后端变量添加:
```javascript
<div
class="serviceDate"
:style="{
'background-image': `url(${require('../../assets/weekComment/bannerCard_' + serviceInfo.code +'.png')})`,
}"
>
</div>
3.若是img元素:
<img :src="require('@/assets/contract/'+(chechItem.active?'selected':'select')+'.png')" >