寫Vue要動態載入圖片路徑遇到的問題,所以用Vue語法範例

v-bind:style="{'background-image':`url(../Assets/Ad/${ad_path})`}"

Vue綁定style,帶入 ad_path 參數,若 ad_path 帶有空白
比如說 ad_path 是個黨名 "im file name"
那麼Vue渲染後 background-image  樣式不會顯示
這時路徑用encodeURI包起來即可

v-bind:style="{'background-image':`url(../Assets/Ad/${encodeURI(ad_path)})`}"

這樣就能正常顯示了~
資料夾和檔名都可以使用空白字元,只是不常使用
這次剛好遇到,紀錄一下

 

arrow
arrow
    文章標籤
    css vue
    全站熱搜
    創作者介紹
    創作者 jack1213 的頭像
    jack1213

    尋找魔豆的傑克

    jack1213 發表在 痞客邦 留言(0) 人氣()