Selaa lähdekoodia

处理ios系统下窗体闪烁的bug

sa03 5 vuotta sitten
vanhempi
commit
b0b4a8ee81
2 muutettua tiedostoa jossa 17 lisäystä ja 20 poistoa
  1. 0 20
      _src/components/chatMini/chatMini.vue
  2. 17 0
      _src/mixins/index.js

+ 0 - 20
_src/components/chatMini/chatMini.vue

@@ -238,9 +238,6 @@ export default {
       let ele = this.$refs.chatInput
       this.inputHeight = 'auto'
 
-      // 处理ios系统下窗体闪烁的bug
-      this.fixIOS()
-
       this.$nextTick(() => {
         this.inputHeight = Math.max(18, Math.min(ele.scrollHeight, 75)) + 'px'
       })
@@ -700,23 +697,6 @@ export default {
       e.preventDefault()
       return false
     },
-    /**
-     * @des 处理ios系统下窗体闪烁的bug
-     * @param {boolean} flag {true: 激活修复状态, false: 恢复原始状态}
-     */
-    fixIOS (flag = true) {
-      if (flag) {
-        this.$refs.scrollWrap.style.overflowY = 'hidden'
-      } else {
-        this.$refs.scrollWrap.style.overflowY = 'scroll'
-      }
-    },
-    handleFocus () {
-      this.fixIOS()
-    },
-    handleBlur () {
-      this.fixIOS(false)
-    },
     placeEnd (el) {
       var range = document.createRange()
       range.selectNodeContents(el)

+ 17 - 0
_src/mixins/index.js

@@ -79,6 +79,8 @@ export const chatInputMixin = {
   },
   watch: {
     inputMsg (val, newval) {
+      this.fixIOS()
+
       this.handleSelectionChange()
     }
   },
@@ -102,9 +104,13 @@ export const chatInputMixin = {
       return false
     },
     handleFocus () {
+      this.fixIOS()
+
       document.addEventListener('selectionchange', this.handleSelectionChange)
     },
     handleBlur () {
+      this.fixIOS(false)
+
       document.removeEventListener('selectionchange', this.handleSelectionChange)
       this.updateChatInputFocus(false)
     },
@@ -115,6 +121,17 @@ export const chatInputMixin = {
       let selectionStart = this.$refs.chatInput.selectionStart
       let prevStr = this.inputMsg.slice(0, selectionStart)
       this.selectionAfterAt = /@$/.test(prevStr)
+    },
+    /**
+     * @des 处理ios系统下窗体闪烁的bug
+     * @param {boolean} flag {true: 激活修复状态, false: 恢复原始状态}
+     */
+    fixIOS (flag = true) {
+      if (flag) {
+        this.$refs.scrollWrap.style.overflowY = 'hidden'
+      } else {
+        this.$refs.scrollWrap.style.overflowY = 'scroll'
+      }
     }
   }
 }