1.vue2.0为例,在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>
所有评论(0)