wxss无法使用本地图片 uniapp do-not-use-local-path

微信小程序使用background-image没有图片显示

报错信息:图片-do-not-use-local-path
pages/index/index.wxss 中的本地资源图片无法通过 WXSS 获取
解决方法:可以使用网络图片,或者 base64,或者使用标签。

.container {
    display: flex;
    background-repeat:no-repeat;
    background-image: url('../../images/user_bg.jpg');
}

将图片user_bg.jpg 转换为base64,地址 http://imgbase64.duoshitong.com/
在这里把要使用的图片转换一把,然后将得到的字符放到background-image属性值中:
重新编码 如下,就可以得到你想要的效果了:

.container {
    display: flex;
    background-repeat:no-repeat;
    background-image: url('data:image/jpeg;base64,。。。。。。。');
}

你可能感兴趣的:(前端-CSS,微信小程序,小程序,微信)