微信小程序中由于限制原因,不能直接给view设置本地的图片。所以有以下几种解决方法
1.使用网络图片
2.使用base64格式
3.使用image来装载本地的图片,然后作为 界面背景
前面两种都很简单,下面我们重点来讲讲第三种。一般大家的苦恼都是这么把imageview放到界面的最下面。那么下面直接上代码。
wxml
<view class="root">
<image class='background-image' src='../res/login_bg.png' mode="aspectFill"></image>
<view class="content">
</view>
</view>
wxss
.root {
width: 100%;
height: 100%;
background-color: #70c7da;
position: relative;
}
.background-image{
height : 100%;
position: absolute;
width: 100%;
left: 0px;
top: 0px;
}
.content{
position: absolute;
width: 100%;
height: 100%;
left: 0px;
top: 0px;
}
好了,搞定。只要用相对布局,就可以实现了。类似android的相对布局。现在只要把内容全部写道content中就行了