uniapp真机背景图不显示问题
有时候uniapp更新后,运行到浏览器可以看到背景图片。但打包wgt后,在真机上就看不到背景图片。可以采用以下方式
(下面有条件编译,根据不同的情况分别编译)
<view class="container"
<!-- #ifdef APP-PLUS -->
:style="{backgroundImage: 'url(../../static/register_bg_image.png)'}"
<!-- #endif -->
<!-- #ifdef H5||MP-WEIXIN -->
:style="{backgroundImage: `url(${loginBackgroundImage})`}"
<!-- #endif -->
>
</view>
在script中引入import loginBackgroundImage from “…/…/static/register_bg_image.png”;
在data中使用使用该变量。因为小程序是使用网络资源。
data() {
return {
loginBackgroundImage: loginBackgroundImage,
// #ifdef MP
loginBackgroundImage:'https://img.ugomt.com/static/register_bg_image.png',
// #endif
}
}