vue如何解决文本框被键盘遮住的问题

主要代码是:
document.getElementById(this.FullScreenId).scrollTop = document.getElementById(this.FullScreenId).scrollHeight
父组件:

<template>

  <div class="home">

    <div id="testFullScreenId" class="pageFullScreen">

      <div></div>

      <HelloWorld

        type="test"

        FullScreenId="testFullScreenId"

        v-model="inputVal"

        @input="input"

      ></HelloWorld>

      <br />

      <button @click="sub">获取input值</button>

      <br />

      <HelloWorld

        type="test"

        FullScreenId="testFullScreenId"

        v-model="inputVal"

        @input="input"

      ></HelloWorld>

    </div>

  </div>

</template>

<script>

import HelloWorld from "@/components/HelloWorld.vue";

export default {

  name: "HomeView",

  components: {

    HelloWorld,

  },

  data() {

    return {

      inputVal: "",

    };

  },

  created() {},

  mounted() {},

  methods: {

    input(e) {

      console.log(e);

    },

    sub() {

      alert(this.inputVal);

    },

  },

};

</script>

<style scoped>

.pageFullScreen {

  background-color: aqua;

  height: 100%;

  position: absolute;

  top: 0;

  right: 0;

  bottom: 0;

  left: 0;

  overflow: auto;

}

</style>

子组件:

<template>

  <div class="hello">

    <div class="inputList">

      <input :type="type" @input="inputListInput($event)" />

    </div>

  </div>

</template>

<script>

export default {

  name: "HelloWorld",

  props: {

    type: {

      // 文本框类型

      type: String,

      default: "text",

    },

    FullScreenId: {

      // 文本框被键盘遮住

      type: String,

      default: "",

    },

  },

  data() {

    return {};

  },

  created() {},

  mounted() {

    // window.onresize监听页面高度的变化

    window.onresize = () => {

      return (() => {

        // window.scroll(0, 0) // 滚到顶部

        document.getElementById(this.FullScreenId).scrollTop =

          document.getElementById(this.FullScreenId).scrollHeight;

      })();

    };

  },

  methods: {

    // 键盘输入

    inputListInput(e) {

      this.$emit("input", e.target.value);

    },

  },

};

</script>

<style scoped lang="scss">

</style>

  • 25
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值