uni-app官網背景圖片介紹:https://uniapp.dcloud.io/frame?id=%e8%83%8c%e6%99%af%e5%9b%be%e7%89%87
uni-app官網介紹,插入本地背景圖片超過40kb時,會有性能問題,若必須使用,可將圖片轉換成base64格式后使用,或將圖片放到服務器上,使用網絡地址調用。
實際測試 background-image: url('~@/static/Newyear/3c/3c-di.png'); 插入背景圖片超過40kb將不顯示
本篇博客介紹另外一種方法,可插入本地背景圖片超過40kb
dcloud社區相關問題:https://ask.dcloud.net.cn/question/62417
動態設置background-image路徑
<view class="center" :style="{backgroundImage:`url(${imageSrc})`,backgroundSize: 'cover'}"> </view>
Tips:backgroundImage為駝峰命名,使用background-image將報錯
引入靜態文件,imageSrc賦值
<script> import imageSrc from "@/static/Newyear/3c/3c-di.png" export default { data() { return { imageSrc: imageSrc } } } </script>
Tips:本地圖片命名不能使用中文,否則將編譯報錯
End!