Friday, March 3, 2017

Using props in single Vue component file

Need to use my variables in the Vue JS code but currently not working.

I am using Laravel and Vue with a single component vue file.

I have duplicated the example component file and have a test id passed into the template as a prop:

<template :auth_user="" :vehicle_id="1">
    <form class="form">
        <!-- Form content -->
    </form>
</template>

And then in my JS:

<script>
    export default {
        props: ['vehicle_id'],
        mounted() {
            var $this = this;
            console.log($this.vehicle_id);
        }
    }
</script>

This is always undefined but pretty sure it should work? Any help?



via Lovelock

Advertisement