[Vuejs]-How to refresh the vue component from method

0👍

Add a key to the component like this

<my-component :key="identifier" />

And in the data add a variable identifier

  data() {
    return {
      identifier: +new Date()
    };
  },
  methods: {
    refreshComponent() {
      this.identifer = +new Date();
    }
  },

What we are doing here is we have added a key to the component, so when we change the key, the component will refresh.

Leave a comment