vue刷新页面

    技术2022-07-10  148

    App.vue写入

    <template>     <div id="app">         <router-view v-if="isRouterAlive"></router-view>     </div> </template> <script>     export default {         name: 'App',         provide () {    //父组件中通过provide来提供变量,在子组件中通过inject来注入变量。                                                          return {                 reload: this.reload                                                           }         },         data() {             return{                 isRouterAlive: true                    //控制视图是否显示的变量             }         },         methods: {             reload () {                 this.isRouterAlive = false;            //先关闭,                 this.$nextTick(function () {                     this.isRouterAlive = true;         //再打开                 })              }         },     } </script> 需要刷新的页面

    引入

    inject:['reload'], //注入App里的reload方法

    export default {     inject:['reload'],                                 //注入App里的reload方法     data () {         return {         .......         }     }, 需要时调用

    this.reload();

    Processed: 0.010, SQL: 12