关于uniapp css背景图不能用本地文件的解决办法

在这里插入图片描述

1.小于40kb的直接这样设置,
2.图片大于40k可以自己转化

转化base64
在这里插入图片描述
生成图片base64字符串,拷贝到项目中,代码如下

<template>
	<view class="container" :style="{backgroundSize: 'cover'}">
	</view>
</template>

<script>
</script>

<style >
	.container{
		width:690rpx;
		height:1160rpx;
		margin: 30rpx 30rpx;
		background-image:url('base64字符串拷贝到这里');
	}
</style>
注意: 至于下面这种很多文章介绍的方法,小程序和h5有效,但是手机真机上却不显示,所以官方推荐的base64方法才是通用的解决方法。
<template>
	<view class="index" :style="{backgroundImage:`url(${indexBackgroundImage})`,backgroundSize: 'cover'}">
		<!--你的内容-->
	</view>
</template>
 
<script>
	import indexBackgroundImage from "@/static/img/account_index.jpg"
	export default {
		data() {
			return {
				indexBackgroundImage:indexBackgroundImage
			}
		},
		methods: {	
		}
	}
</script>
<style lang="scss" scoped="">
</style>

参考:
https://uniapp.dcloud.io/frame?id=背景图片

参考地址base图片转化文章

https://blog.csdn.net/weixin_43343144/article/details/90300788

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值