vue 无感刷新当前页面,主要方法如下
修改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
}
},
methods: {
reload () {
this.isRouterAlive = false
this.$nextTick(function () {
this.isRouterAlive = true
})
}
}
}
</script>
然后再对应的组件里面使用如下,首先在子组件中inject注入进去,在需要的地方,直接调用this.reload()即可
export default {
name: 'Layout',
inject: ['reload'],
components: {
Navbar,
Sidebar,
AppMain,
HeadMenu
},
methods: {
flush() {
this.reload() //通过inject注入进来的
}
}
}