当在移动端输入时,软键盘会把底部导航栏顶起
    解决办法:监测页面高度变化,软键盘弹出时,页面高度会变小,此时隐藏底部导航栏

    在 store 的 state 中添加一个 show 状态,用于控制导航栏的显示或隐藏

    1. state: {
    2. // ...
    3. show: true,
    4. },
    5. mutations: {
    6. changeHidden(state, payload) {
    7. state.show = payload.show
    8. },
    9. // ...
    10. }

    在组件中使用 state

    1. <template>
    2. <div class="wrapper">
    3. <slot />
    4. <Docker v-show="store.state.show"/>
    5. </div>
    6. </template>
    7. <script lang="ts" setup>
    8. import { useStore } from 'vuex';
    9. import Docker from './Docker.vue';
    10. const store = useStore()
    11. </script>

    在 App 组件中添加事件监听和状态监测

    1. <script lang="ts" setup>
    2. import { onMounted, watchEffect,ref } from 'vue';
    3. import { useStore } from 'vuex';
    4. const store = useStore()
    5. const showHeight = ref(window.document.documentElement.clientHeight)
    6. const docHeight = window.document.documentElement.clientHeight
    7. onMounted(()=>{
    8. window.onresize = () => {
    9. showHeight.value = window.document.documentElement.clientHeight
    10. }
    11. })
    12. watchEffect(() => {
    13. if(showHeight.value < docHeight) {
    14. store.commit('changeHidden', {show: false})
    15. } else {
    16. store.commit('changeHidden', {show: true})
    17. }
    18. })
    19. </script>