I'm trying to create a menu in vue.js. I have 2 components - Navigation and NavLink. I created an array of links in App.vue file and passed it as a props to Navigation component. In the Navigation component I'm using NavLink to create the li element for each item in the array.
App.vue
<template>
<div class="container">
<div class="row">
<div class="col-xs-12 col-sm-8 col-sm-offset-2 col-md-6 col-md-offset-3">
<app-nav></app-nav>
<hr />
<router-view></router-view>
</div>
</div>
</div>
</template>
<script>
import Navigation from "./components/Navigation.vue";
export default {
components: {
"app-nav": Navigation
}
};
</script>
<style>
</style>
Navigation.vue
<template>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="collapse navbar-collapse" id="navbarTogglerDemo02">
<ul class="navbar-nav mr-auto mt-2 mt-lg-0">
<nav-link v-for="link in links"></nav-link>
</ul>
</div>
</nav>
</template>
<script>
import NavLink from "./NavLink.vue";
export default {
data() {
return {
links: ["Home", "Login", "Shop"]
};
},
components: {
"nav-link": NavLink
}
};
</script>
<style>
</style>
NavLink.vue
<template>
<li class="nav-item">
<a class="nav-link" href="#"></a>
</li>
</template>
<script>
export default {
props: ["links"]
}
</script>
<style>
</style>
It actually create 3 elements of 'NavLink' but the link title itself is empty, how can I pass the title of array items to the NavLink component?
links
data is not passed in theapp-nav
component – rcbgalido