0

I'm running Vue.js with vue-router, and are trying to pass parameters to my template.

This is my route:

{ path: '/car/:id', component: car, props: true },

This is my template Car.vue:

<template>
    <h2>{{ id }}</h2>
</template>

<script>
    export default {
        props: ['id']
    },
    methods: {
        getCar: function () {
        axios.get('http://my-api/car/' + id)
            .then((response) => {
                this.car = response.data
            })
            .catch((error) => {
                console.log(error)
            })
    }
</script>

I'm getting the error:

  ✘  http://eslint.org/docs/rules/no-undef  'id' is not defined

But the id is shown in h2, but not used in the api call.

1
  • You should access the props using this.id not id Commented Jun 11, 2018 at 10:15

1 Answer 1

2

Use your props using this. this.id will solve your problem.

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.