[Vuejs]-Vue JS access data from parent component

1👍

You need to declare links as a prop in navbar.vue, otherwise Vue will ignore it:

export default {
    name: 'navbar',
    props: ['links'], // declare links as a prop
    data () {
        return {
            brand: 'Vue Website',
        }
    },
}

Then in the parent you can use it:

<navbar :links="links"></navbar>

See: https://v2.vuejs.org/v2/guide/components.html#Props

1👍

You forgot to "bind" your property "links".

Instead of

<navbar links="links"></navbar> 
// This will give you a string "links"

Use:

<navbar :links="links"></navbar> 

More information:
https://v2.vuejs.org/v2/guide/components.html#Dynamic-Props

Leave a comment