inject刷新

1、修改App.vue

  <template>

    <div id="app">

      <router-view v-if="isRouterAlive"></router-view>

    </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>

2、到需要刷新的页面引用

  export default {

    inject: ["reload"],

    data() {

      return {

      }

    },

    methods: {

      //调用

      this.reload()

    }

  }

posted @ 2020-01-08 17:47  郑正正  阅读(627)  评论(0编辑  收藏  举报
Live2D