I'm facing a problem with importing Objects from the App.vue file to a component. But first I should explain the purpose of this project. There's a component (navigation-drawer) and an App.vue file. The Navigation drawer has vue props in it, which you can dynamically change in the App.vue file. The problem with that is that I can only use as many links as there are in the Navigation-Drawer file.
I would like to edit it so I can use as many links as I need, without even having to open the Navigation-Drawer.vue file. Before I go into more detail, here are the files with the props & limited amount of links:
App.vue
<template>
<div id="app">
<navigation-drawer
name1="TFBern"
name2="Stackoverflow"
name3="YouTube"
name4="Google"
link1="https://vuejs.org"
link2="https://stackoverflow.com"
link3="https://youtube.com"
link4="https://google.com"
/>
<img alt="Vue logo" src="./assets/logo.png">
<HelloWorld msg="Welcome to Your Vue.js App"/>
</div>
</template>
<script>
import HelloWorld from './components/HelloWorld.vue'
import NavigationDrawer from './components/Navigation-Drawer.vue'
export default {
name: 'App',
components: {
HelloWorld,
NavigationDrawer
}
}
</script>
Navigation-Drawer.vue
<template>
<div class="navigationdrawer">
<span @click="openNav" style="fontsize:30px;cursor:pointer;display:flex;justify-content:center;">☰</span>
<div id="mySidenav" class="sidenav">
<a href="javascript:void(0)" class="closebtn" @click="closeNav">×</a>
<a v-bind:href="link1">{{ name1 }}</a>
<a v-bind:href="link2">{{ name2 }}</a>
<a v-bind:href="link3">{{ name3 }}</a>
<a v-bind:href="link4">{{ name4 }}</a>
</div>
</div>
</template>
<script>
export default {
name: 'NavigationDrawer',
props: {
name1: String,
name2: String,
name3: String,
name4: String,
link1: String,
link2: String,
link3: String,
link4: String
},
methods: {
openNav() {
document.getElementById('mySidenav').style.width = '15%'
},
closeNav() {
document.getElementById('mySidenav').style.width = '0%'
}
}
}
</script>
Now, what I had in mind was to create a js object, which can import the links from App.vue into the Drawer. Something like this:
<navigation-drawer links="[ {title="Google", link="www.google.ch"} , {title="Youtube", link="www.youtube.com"} , {title=…, link=…} ]"
I don't really know how to do it... Can anyone help?
Thank you.