app.vue
onMounted(async () => {
// 监听浏览器的beforeunload事件
window.addEventListener('beforeunload', (event) => {
// 如果条件满足(例如当前不是默认页面时),重定向到默认页
if (route.path !== '/') {
router.push('/');
}
});
// 组件卸载前移除事件监听,避免内存泄露
onUnmounted(() => {
window.removeEventListener('beforeunload', () => {});
});
})