vue3 全局监听浏览器窗口变化,刷新当前页面布局

添加文件

App.vue

代码

<template>
  <!-- element-plus汉化处理 -->
  <el-config-provider :locale="zhCn">
    <router-view v-if="render"/>
  </el-config-provider>
</template>

<script setup>
import { ElConfigProvider } from 'element-plus'
import zhCn from 'element-plus/lib/locale/lang/zh-cn'
import { ref, onMounted, nextTick } from 'vue'

let render = ref(true)

onMounted(()=>{
  window.addEventListener('resize', reload)
})
const reload = () => {
  render.value = false;
  nextTick(()=>{
    render.value = true;
  })
}
</script>
posted @ 2023-07-25 14:55  helloSWZ  阅读(1518)  评论(0编辑  收藏  举报