1. window.onload 来刷新页面, 页面会白一下,交互效果不好
2. router.go(0) 来刷新页面, 页面会白一下,交互效果不好
3. provide, inject配合router来刷新页面
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>
- 在需要调用刷新的组件中
import { inject } from 'vue-demi'
const reload = inject('reload')
const updateFun = () => {
reload()
}
网友评论