Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

christopher's avatar

Vuejs get url param

Half the day i am trying to get the url param in vuejs :)

module.exports = {
    template: require('./show.html'),

    ready: function() {
        this.fetchMessages();
    },

    methods: {
        fetchMessages: function(params) {
            this.$http.get('http://domain.dev/api/library/' + params.slug , function(course) {
                this.$set('course', course);
                console.log(params);
            });
        }
    }

};

But i am getting the error, that slug is not defined. If i use { {$route.params.slug} } in my view, it returns the slug. ( http://vuejs.github.io/vue-router/route.html )

The API returns the slug: http://domain.dev/api/library/slug So for example i have the url http://domain.dev/dashboard#!/library/shopware-grundlagen

If i hardcode the API Url ( http://domain.dev/api/library/shopware-grundlagen ) it works and i am getting all my details about the item, but of course it must be dynamicly :)

Could someone help me to get this thing working?

0 likes
5 replies
ahmediz's avatar

@thomaskim I tried it but it gives me "Cannot read property 'params' of undefined"

2 likes
Kjaal's avatar

Hey I just wanted update this thread since Vue-Router has been updated since 2 years ago.

New way of fetching URL Query is through the "currentRoute" so: this.$router.currentRoute.query

2 likes

Please or to participate in this conversation.