uni-app 背景圖片綁定問題

uni-app由於的圖片處理爲了兼容小程序,禁止了使用本地圖片(相對或者絕對路徑) ,可以使用網絡圖片和base64格式的圖片

如果非常想用本地圖片,這圖片大小不能超過40kb,否則需要轉換成base64

在引用圖片的時候我發現我一開始我把圖片放在再index文件夾(首頁文件夾)下面,

然後編譯到小程序我發現小程序裏面index文件夾(首頁文件夾)裏面並沒有圖片

也就是圖片放在了首頁等等html文件的文件夾中的圖片不能編譯到其他環境

圖片需要另創建一個文件夾來存放,此時就可以編譯到其他平臺都有這張圖片了

<template>
	<view class="app">
		<view class="profile-head" :style="{backgroundImage:'url('+imgUrl+')'}">
			<view class="profile-img">
				<image src="../../static/image/my/aaas.jpg" mode="widthFix" ></image>
			</view>
		</view>
	</view>
</template>

<script>
	let app  = ''
	export default {
		data() {
			return {
				imgUrl:"../../static/image/my/aaas.jpg"
			}
		},
		onLoad() {
			app = getApp()
			// console.log(app.globalData.systemInfo)
			console.log(this)
		
		},
		methods: {
			
		}
	}
</script>
<template>
	<view class="app">
		<view class="profile-head" style="background-image:url(../../static/image/my/aaas.jpg)">
			<view class="profile-img">
				<image src="../../static/image/my/aaas.jpg" mode="widthFix" ></image>
			</view>
		</view>
	</view>
</template>

頁面效果

在這裏插入圖片描述
在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章