vue实现页面刷新

tech2022-12-19  110

1.在app.vue根组件:

<template> <div id="app"> <router-view v-if="isRouterAlive" /> </div> </template> <script> export default { provide() { return { reload: this.reload, }; }, data() { return { isRouterAlive: true, }; }, methods: { reload() { this.isRouterAlive = false; this.$nextTick(function () { this.isRouterAlive = true; }); }, }, }; </script> <style lang="scss"> #app { } </style>

2.在需要刷新的页面加入(和methods同级):

inject:['reload']

3.引用:

this.reload();
最新回复(0)