[Vuejs]-How to auto change page with vue-router?

2👍

If you wish to transition from HelloWorld to MyPage component then use created or mounted hook of the HelloWorld component like this:

created() {
    setTimeout(() => {
        // You can also use replace() instead of push()
        this.$router.push('/myPage');
    }, 2000);
}

Read more about hooks here.

1👍

You will have to do that in your HelloWorld.vue file. You will have something like this in the mount function of your HelloWorld.vue file

mounted() {
    setTimeout(() => {
       this.$router.push('/next-route')
    }, 2000)
}

Hope that helps

Leave a comment