How to pass url parameters to Vuejs

后端 未结 5 2013
感情败类
感情败类 2021-02-13 05:14

I\'m building an app with laravel and VueJs and I was wondering how to pass a url parameter like the user slug or the user id to vuejs in a proper way to be able to use that pa

5条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-13 05:22

    I suppose you are building a component. Let's say, you have a button inside that component and when is clicked, you wanna perform an action (AJAX request, or just redirect).

    In this case you pass the URL as parameter to the component and you can use it inside.

    HTML:

    
    

    Your component JS:

    export default {
        props: {
            loginUrl: {required: true},
        },
        ...
    }
    

    Then you can access the param in the component as this.loginUrl.

    Please notice that param name difference in HTML part as dash-notatinon and in JS as camelCase.

提交回复
热议问题