dhaval's avatar

How to get slug from url ?

let me explain with example on that I am working.My project is in laravel 5.3.

when I open http://localhost/gift_india/brand/baskin-robbins url it's call brand_detail.blade.php file so on this url baskin-robbins is my slug. so I want to pass baskin-robbins to vue js and want to get data for this brand item.

brand_detail.blade.php file

<brand-detail></brand-detail>

@{{detail}}

brand_detail.js file

Vue.component('brand-detail', {

template: '#brand-detail-template',

data: function(){

return {

    detail: []

}

},

created: function(){ var slug = this.$route.params.slug; // here I'm getting error that Uncaught TypeError: Cannot read property 'params' of undefined console.log(slug);

axios.get('brand_detail/:slug')
    .then(function (response) {
        console.log(response.data);

    })
    .catch(function (error) {
        console.log(error.data);
    });

} });

new Vue({

el: '#container_detail'

})

In my blade_detail.blade.php file I have include below js files.

How can I get this ?

0 likes
1 reply

Please or to participate in this conversation.