1.app.vue
<template>
<div id="app">
<!--<img src="./assets/logo.png">-->
<router-view v-if="isRouteAlive"/>
</div>
</template>
<script>
export default {
name: 'App',
provide () {
return {
reload: this.relord
}
},
data () {
return {
isRouteAlive: true
}
},
methods: {
reload () {
this.isRouteAlive = false
this.$nextTick (() => {
this.isRouteAlive = true
})
}
}
}
</script>
2.需要刷新的组件
<template>
<div class="hello">
<el-button @click="refresh">刷新</el-button>
</div>
</template>
<script>
export default {
name: 'HelloWorld',
inject: ['reload'],
created () {
console.log('created-测试')
},
mounted () {
console.log("mounted-测试")
},
methods: {
refresh () {
this.reload()
}
}
}
</script>
网友评论