最近項目遇到問題總結
- 2020 年 3 月 18 日
- 筆記
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); },