欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

vue 解決文本框被鍵盤遮住的問題

 更新時間:2019年11月06日 15:03:47   作者:echo_Ae  
今天小編就為大家分享一篇vue 解決文本框被鍵盤遮住的問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧

如下所示:

我把它寫成了組件

主要代碼是

document.getElementById(this.FullScreenId).scrollTop = document.getElementById(this.FullScreenId).scrollHeight

我這邊把div滿屏了看下面css就知道了

你也可以使用body,這個你行百度一下就可以了

注意點是css

/* 頁面滿屏 */
.pageFullScreen {
 height: 100%;
 position: absolute;
 top: 0;
 right: 0;
 bottom: 0;
 left: 0;
 overflow: auto;
}

父組件

<style>
</style>
<template>
 <div id="testFullScreenId" class="pageFullScreen">
  <div style="height: 500px; background-color: #eee;overflow-y: scroll;-webkit-overflow-scrolling: touch;"></div>
   <inputList type="test" @inputListClick="inputListClick" FullScreenId="testFullScreenId" v-model="inputVal" @inputListFocus="focus" @inputListBlur="blur"></inputList>
   <br />
   <button @click="sub">獲取input值</button>
   <br />
   <inputList type="test" @inputListClick="inputListClick" FullScreenId="testFullScreenId" v-model="inputVal" @inputListFocus="focus" @inputListBlur="blur"></inputList>
 </div>
</template>
<script>
 import inputList from '../../components/input' // input
 export default {
  components: {
   inputList
  },
  data() {
   return {
    imagesUrl: { // 排版圖片使用懶加載
    },
    inputVal: ''
   }
  },
  created() {
  },
  mounted() {
  },
  methods: {
   focus(e) {
    console.log(e)
   },
   blur(e) {
    console.log(e)
   },
   inputListClick(e) {
    console.log(e)
   },
   sub() {
    alert(this.inputVal)
    console.log(this.inputVal)
   }
  }
 }
</script>

子組件

<style>
.inputList {}
</style>
<template>
 <!-- 父組件使用v-model發(fā)送input事件就可以接收到了 -->
 <div class="inputList">
  <input :type="type" @click="inputListClick($event)" @input="inputListInput($event)" @focus="inputListFocus($event)" @blur="inputListBlur($event)">
 </div>
</template>
<script>
 export default {
  name: 'inputList',
  props: {
   type: { // 文本框類型
    type: String,
    default: 'text'
   },
   FullScreenId: { // 文本框被鍵盤遮住
    type: String,
    default: ''
   }
  },
  data() {
   return {
    imagesUrl: { // 排版圖片使用懶加載
    },
    pageHeightOne: '', // 頁面高度
    pageHeightTow: ''
   }
  },
  created() {
  },
  mounted() {
   // window.onresize監(jiān)聽頁面高度的變化
   window.onresize = () => {
    return (() => {
     // window.scroll(0, 0) // 滾到頂部
     document.getElementById(this.FullScreenId).scrollTop = document.getElementById(this.FullScreenId).scrollHeight
    })()
   }
  },
  methods: {
   // 鍵盤輸入
   inputListInput(e) {
    if (typeof e.target.value === 'string') {
     if (/[\u4e00-\u9fa5]/.test(e.target.value)) {
      e.target.value = ''
     } else {
      // console.log('合格')
     }
    } else {
     console.log('數(shù)據(jù)類型不正確')
    }
    this.$emit('input', e.target.value)
   },
   // 獲取焦點
   inputListFocus(e) {
    // console.log(e)
    this.$emit('inputListFocus', 'focus')
   },
   // 失去焦點
   inputListBlur(e) {
    // console.log(e)
    this.$emit('inputListBlur', 'blur')
   },
   // 點擊
   inputListClick(e) {
    this.$emit('inputListClick', 'click')
   }
  }
 }
</script>

相關(guān)文章

  • Vue中的循環(huán)遍歷與key值原理解讀

    Vue中的循環(huán)遍歷與key值原理解讀

    這篇文章主要介紹了Vue中的循環(huán)遍歷與key值原理,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2023-05-05
  • Vite3結(jié)合Svelte3使用@import導(dǎo)入scss樣式

    Vite3結(jié)合Svelte3使用@import導(dǎo)入scss樣式

    這篇文章主要為大家介紹了Vite3結(jié)合Svelte3使用@import導(dǎo)入scss樣式實現(xiàn)實例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-06-06
  • vue中axios的二次封裝實例講解

    vue中axios的二次封裝實例講解

    在本篇文章里小編給大家整理了關(guān)于vue中axios的二次封裝實例以及相關(guān)知識點總結(jié),需要的朋友們可以學(xué)習(xí)下。
    2019-10-10
  • vue2.0 如何在hash模式下實現(xiàn)微信分享

    vue2.0 如何在hash模式下實現(xiàn)微信分享

    這篇文章主要介紹了vue2.0 如何在hash模式下實現(xiàn)微信分享,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2019-01-01
  • 淺談Vue.js 組件中的v-on綁定自定義事件理解

    淺談Vue.js 組件中的v-on綁定自定義事件理解

    這篇文章主要介紹了淺談Vue.js 組件中的v-on綁定自定義事件理解,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-11-11
  • Vue.js 使用v-cloak后仍顯示變量的解決方法

    Vue.js 使用v-cloak后仍顯示變量的解決方法

    這篇文章主要介紹了Vue.js 使用v-cloak后仍顯示變量的解決方法 ,文中給大家提到了v-cloak的用法,需要的朋友可以參考下
    2018-11-11
  • 在IDEA中配置eslint和prettier的全過程

    在IDEA中配置eslint和prettier的全過程

    日常開發(fā)中,建議用可以用Prettier做代碼格式化,然后用eslint做校驗,下面這篇文章主要給大家介紹了關(guān)于在IDEA中配置eslint和prettier的相關(guān)資料,需要的朋友可以參考下
    2024-02-02
  • Ant?Design?Vue?Pagination分頁組件的封裝與使用

    Ant?Design?Vue?Pagination分頁組件的封裝與使用

    這篇文章主要介紹了Ant?Design?Vue?Pagination分頁組件的封裝與使用方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2023-04-04
  • vue動態(tài)注冊組件實例代碼詳解

    vue動態(tài)注冊組件實例代碼詳解

    寫本篇文章之前其實也關(guān)注過vue中的一個關(guān)于加載動態(tài)組件is的API,最開始研究它只是用來實現(xiàn)一個tab切換的功能,需要的朋友可以參考下
    2019-05-05
  • 對vue中v-if的常見使用方法詳解

    對vue中v-if的常見使用方法詳解

    今天小編就為大家分享一篇對vue中v-if的常見使用方法詳解,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-09-09

最新評論