使用location.reload()html
或者是vue
路由的 this.$router.go(0)數組
進行刷新的時候,是會出現一陣的空白區域的,由於是整個頁面的刷新app
,因此比較緩慢,所以使用了provide/inject的方法。ide
在App.vue中寫入如下代碼:函數
<template> <div id="app"> <router-view v-if="isRouterAlive"/> </div> </template> <script> export default { name: "app", //提供一個依賴 provide(){ return { reload:this.reload } }, data(){ return { isRouterAlive:true } }, //聲明reload方法,控制router-view的顯示或隱藏,從而控制頁面的再次加載 methods:{ reload(){ this.isRouterAlive = false; this.$nextTick(function(){ this.isRouterAlive=true }) } } }; </script> <style>
.size{
width:100%;
heigth:100%;
} html,body{
.size; margin: 0; padding: 0; } #app { .size;
}
</style>
子頁面引用this
<script> export default { inject:['reload'] , methods:{ reload(){ this.reload() } } } </script>
provide:選項應該是一個對象或返回一個對象的函數。該對象包含可注入其子孫的屬性。spa
inject:一個字符串數組,或一個對象,對象的 key 是本地的綁定名code