最近项目遇到问题总结
1、ios弹窗输入框,关闭后,页面顶上去不恢复的问题
解决方法:
function temporaryRepair() { const that = this; const windowFocusHeight = window.innerHeight; if (that.windowHeight === windowFocusHeight) { return; } let currentPosition; const speed = 1; // 页面滚动距离 currentPosition = document.documentElement.scrollTop || document.body.scrollTop; currentPosition -= speed; window.scrollTo(0, currentPosition); // 页面向上滚动 currentPosition += speed; // speed变量 window.scrollTo(0, currentPosition); // 页面向下滚动 }
2、输入框限制输入长度,输入emoj表情无法正确计数问题
解决办法:将emoj表情统一处理为一个长度
function descInput() { // 让emoj表情的长度变成1 核心代码是下面2行,其他为业务代码 const regexAstralSymbols = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g; const len = this.info.reason.replace(regexAstralSymbols, '_').length; console.log('输入内容长度1', len); if (len === this.maxCount) { this.tipTxt = this.overLangTxt; this.isTipsShow = true; } this.info.reason = this.info.reason.slice(0, 200); },