App.vue
<template>
<div id="app">
<router-view v-if="lsRouterAlive" />
</div>
</template>
<script>
export default {
provide() {
return {
reload: this.reload
}
},
data() {
return {
lsRouterAlive: true
}
},
methods: {
reload() {
this.lsRouterAlive = false
this.$nextTick(function () {
this.lsRouterAlive = true
window.location.reload();
})
}
},
}
</script>
<style lang="scss">
* {
margin: 0;
padding: 0;
}
body {
width: 100%;
height: 100vh;
background-color: black;
}
</style>
调用的页面
使用inject引入对应的方法
inject: ['reload'],
调用方法
const getWindowInfo = () => {
const windowInfo = {
width: window.innerWidth,
hight: window.innerHeight
}
console.log(windowInfo);
this.reload()
};
window.addEventListener('resize', getWindowInfo);