记录一下在学习中遇到的问题,如果错误还请指正!!!
当按钮固定在了底部,点击输入框时,键盘就把底部的按钮覆盖掉。有的时候想让它被键盘上推,就需要这样来实现了。
//JS代码
data: {
bottom: 0,
isBlur: true,
blurBottom: 0,
goods_name: "",
},
//输入框聚焦时触发事件
onFoucs (e:any) {
this.setData({
bottom: e.detail.height,
isBlur: false
})
},
//输入框失焦时触发事件
onBlur(){
this.setData({
isBlur: true
})
},
视图层以van-field为例子
<van-field
model:value="{{ goods_name }}"
label="商品名称"
placeholder="请输入商品名称"
bind:focus="onFoucs"
bind:blur="onBlur"
/>
<van-button type="primary" size="large" custom-style='position:fixed;width:100%;bottom:{{isBlur ? blurBottom : bottom}}px;' >保存</van-button>
van-button就是按钮,其中style里的position:fixed是让按钮位置固定。
bottom:{{isBlur ? blurBottom : bottom}}px是规定按钮里屏幕底部的距离
其他应用就自行添加啦!