vue项目如何刷新当前页面
- app.vue
<template>
<div id="app">
<router-view v-if="isRouterAlive"></router-view>
</div>
</template>
export default {
name: 'app',
//提供reload方法
provide: function () {
return {
reload: this.reload
}
},
// isRouterAlive控制显示
data: function () {
return {
isRouterAlive: true
}
},
methods:{
// 刷新方法
reload: function () {
this.isRouterAlive = false
this.$nextTick(function () {
this.isRouterAlive = true
})
}
}
}
- 在需要的页面中注入reload
export default{
// 注入reload
inject: ['reload']
}
- 在需要的地方使用reload()方法
this.reload()
除此之外,还有其他方法,比如:this.$route.go(0),loaction.href…等这些方法是刷新整个浏览器,并不具备只刷新当前页面的需求。