- 解释:css背景图片不能使用本地图片,官方给的理由是小程序不支持本地图片,只支持网络访问或者base64。
- 所以uniapp也不支持,但是只要不超过40kb即可。 注意:把下面导入的图片路径改成你自己的。
- 还有:如果图片大小超过40kb是不会自动转换的,需要程序员自己吧图片转换成base64格式
<template>
<view :style="{backgroundImage:`url(${indexBackgroundImage})`,backgroundSize: 'cover'}" >
</view>
</template>
<script>
import indexBackgroundImage from "@/static/images/myInfo/di.png"
export default {
data() {
return {
indexBackgroundImage:indexBackgroundImage
};
},
}
</script>