上代码
<view id="comment" :style="'bottom:'+changeBottomVal">
<image :src="userInfo.avatar?userInfo.avatar:'/static/images/renwu.png'" class="img-t"></image>
<input type="text" placeholder="我来评论" v-model="content" @focus="inputBindFocus" @blur="inputBindBlur" :adjust-position="false" />
<text class="send-btn" @click="sendBtn">发送</text>
</view>
/* */
#comment {
position: fixed;
bottom: 20rpx;
left: 0;
width: 82%;
margin: 0 50rpx;
background: #F2F2F4;
padding: 10rpx 20rpx;
border-radius: 40rpx;
}
.img-t {
width: 70rpx;
height: 70rpx;
border-radius: 50rpx;
float: left;
}
#comment input {
float: left;
line-height: 21px;
height: 70rpx;
font-size: 30rpx;
margin-left: 10rpx;
}
.send-btn {
float: right;
margin-right: 15rpx;
line-height: 70rpx;
font-size: 30rpx;
color: #298815
}
export default {
data() {
return {
changeBottomVal:'20rpx',
}
},
methods: {
inputBindFocus(e) {
// 获取手机键盘的高度,赋值给input 所在盒子的 bottom 值
// 注意!!! 这里的 px 至关重要!!! 我搜到的很多解决方案都没有说这里要添加 px
console.log(e)
this.changeBottomVal = e.detail.height + 'px'
},
inputBindBlur() {
// input 失去焦点,键盘隐藏,设置 input 所在盒子的 bottom 值为0
this.changeBottomVal = 20+'rpx';
},
}
}