2

I have passed an id to the url ie. (http://127.0.0.1:8000/admin/article/32). Now i want to get that id in vue to fetch the data only of that id but i have no idea to get that id in vue

my vue script is down below

 <script>

        export default{

            data() {
                return{

                    articles : [],
                    article: {
                        id :'',
                        title : '',
                        body : '',
                        date :''
                    },
                    article_id: ''
                };
            },

            created() {
                this.fetchArticles();
            },

            methods: {
                fetchArticles() {
                    var page_url = 'http://127.0.0.1:8000/api/admin/article/'+ I want the parameter id here;
                    fetch(page_url)
                        .then(res => res.json())
                        .then(res => {

                            this.article = res.data;
                        })

                        .catch(err => console.log(err));
                }

            }
        };
    </script>

1 Answer 1

5

I am assuming you are not using vue-router.

You can use window.location property to get current url object.

You can get current id using var id = window.location.href.split('/').pop();

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.