wxml:
<view class="section">
<input placeholder="姓名" name="name" bindblur="name" style='background-image: url({{background1}});' />
</view>
<view class="section">
<input type='number' placeholder="电话" bindblur="phone" style='background-image: url({{background2}});' />
</view>
js:
Page({
data: {
// 背景图片
background1: "/images/user1.png",
background2: "/images/iphone.png",
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function(options) {
// 转换背景图片格式
let base641 = wx.getFileSystemManager().readFileSync(this.data.background1, 'base64');
let base642 = wx.getFileSystemManager().readFileSync(this.data.background2, 'base64');
this.setData({
background1: 'data:image/jpg;base64,' + base641,
background2: 'data:image/jpg;base64,' + base642,
});
},
})
wxss:
.section{
width: 100%;
height: 55px;
box-sizing: border-box;
padding-top: 15px;
font-size: 16px;
display: flex;
}
.section input{
width: 90%;
margin: 0 auto;
border-radius: 6px;
background-color:#FFF;
height: 40px;
box-sizing: border-box;
padding-left: 45px;
background-repeat: no-repeat;
background-size: 26px 26px;
background-position: 10px 7px;
}