Skip to content

Commit 7a6c2ee

Browse files
committed
修改路由监听销毁
1 parent 37069da commit 7a6c2ee

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/App.vue

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
</template>
7474

7575
<script>
76-
import { reactive } from 'vue'
76+
import { onUnmounted, reactive } from 'vue'
7777
import Header from '@/components/Header.vue'
7878
import Footer from '@/components/Footer.vue'
7979
import { useRouter } from 'vue-router'
@@ -95,7 +95,7 @@ export default {
9595
number: 1
9696
}
9797
})
98-
router.beforeEach((to, from, next) => {
98+
const unwatch = router.beforeEach((to, from, next) => {
9999
if (to.path == '/login') {
100100
// 如果路径是 /login 则正常执行
101101
next()
@@ -113,6 +113,11 @@ export default {
113113
state.currentPath = to.path
114114
document.title = pathMap[to.name]
115115
})
116+
117+
onUnmounted(() => {
118+
unwatch()
119+
})
120+
116121
return {
117122
state
118123
}

0 commit comments

Comments
 (0)