vue動態設置背景圖片


原始class屬性設置背景樣式

.med-brief {
      width: 100%; min-height: 422px; position: relative; margin-bottom: 20px;  background: url("../../assets/img/tanggou.jpg") no-repeat; background-size: 100%;

通過JavaScript實現動態修改背景圖片

首先html中設置style為 動態綁定 即 :style

<div class="med-brief" :style="backgroundImage">

在JavaScript方法中則可以通過修改綁定backgroundImage實現動態更換背景屬性。

if (item.code === 'CPTP2') {
                  this.backgroundImage = { backgroundImage: 'url(' + this.imgBaseUrl + item.content + ')' } }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM