1.简单方法
//第一种:使用location对象的reload()方法
window.location.reload();
//第二种:使用编程式导航
this.$router.go(0);
2.使用vue中provide和inject(推荐)
在app.vue:
<template><div id="app"><router-view v-if="showRouter"></router-view></div></template><script>export default {name: 'App',provide (){return {reload: this.reload}},data (){return {showRouter: true}},methods: {reload (){this.showRouter = falsethis.$nextTick(()=>{this.showRouter = true})}}}</script><style scoped></style>
在需要刷新的vue组件:
<template><button @click="refreshbtn">刷新</button></template><script>export default {inject: ['reload'],methods: {refreshbtn() {this.reload()}}};</script><style scoped></style>