在前端移动开发中,你可能会遇到以下问题:当页面底部有按钮或图标时,我们点击输入框,数字键盘会悬浮起来。当键盘弹出时,页面高度变小,底部固定定位上升,所以我们只需要在页面高度变小时隐藏底部footer部分,当键盘消失时显示底部footer部分即可解决这个问题。解决方法:检测浏览器的resize事件,当高度过小时,可以判断出现这种情况。这时候把定位改成absolute或者直接隐藏。下面是自定义指令实现的目录结构:footer.ts中的代码resize',()=>{letshowHeight=document.documentElement.clientHeightletwindowHeight=el.windowHeight//默认屏幕高度if(windowHeight>showHeight){el.style.display='none'}else{el.style.display=''}})}}exportdefaultfooterindex.tscodeimportfooterfrom'./footer'exportdefault{install:function(Vue){Vue.directive('footer',footer)}}如果有其他自定义instructions,直接在directives文件夹中新建一个文件,在index文件中写入注册注册。importdirectivesfrom'@/directives'globallyinmain.ts//指令在Vue.use(directives)页面中使用,直接添加到会浮动的元素中:v-footer
