項目中會有需求刷新當前整個頁面,用路由直接刷新的話會有一個白色閃屏出現,怎么解決這個問題呢?
1、首先 我們需要創建一個空白頁面
<template></template> <script> export default { name: 'reload', props: {}, beforeCreate() { const { query } = this.$route; const { path } = query; this.$router.replace({ path: path }); }, render(h) { return h(); } } </script>
2、在需要用到刷新的頁面直接調用
const { fullPath } = this.$route; this.$router.replace({ path: "/redirect", query: { path: fullPath } });
注:如果還有其他解決方案 歡迎留言補充交流哦~