Fetching query parameters in Vue.js

You can access the $route object from components as given below.

Console.log(this.$route.test)

If you don’t have router object defined, define a new router object. Select a mode. First, include the VueRouter in Vue JS core.

<script src="https://unpkg.com/vue-router"></script>

Then declare your routes inside the routes list. The main app must know the router exists so declare it inside main. The route instance holds all the information about the current route.

<script src="https://unpkg.com/vue-router"></script>

var router = new VueRouter({

    mode: 'history',

    routes: []

});

var vm =  new Vue({

    router,

    el: '#app',

    mounted: function() {

        q = this.$route.query.q

        console.log(q)

    },

});