1. window.onload 來(lái)刷新頁(yè)面, 頁(yè)面會(huì)白一下,交互效果不好
2. router.go(0) 來(lái)刷新頁(yè)面, 頁(yè)面會(huì)白一下侣诺,交互效果不好
3. provide, inject配合router來(lái)刷新頁(yè)面
1.在app.vue中
<template>
<router-view v-if="isRouterActive"></router-view>
</template>
<script lang="ts" setup>
import { ref, provide, nextTick } from 'vue-demi'
const isRouterActive = ref(true)
provide('reload', () => {
isRouterActive.value = false
nextTick(() => {
isRouterActive.value = true
})
})
</script>
- 在需要調(diào)用刷新的組件中
import { inject } from 'vue-demi'
const reload = inject('reload')
const updateFun = () => {
reload()
}