Answer the question
In order to leave comments, you need to log in
How to store a component in an array in vue?
Good afternoon.
I'm getting svg icons for social networks as a component, and I want to store them in an array.
<template>
<ul class="social-links">
<li v-for="item in socials" :key="item.id">
<g-link :to="item.url">{{ item.icon }}</g-link>
</li>
</ul>
</template>
<script>
import Facebook from '~/assets/svg/facebook.svg';
import Twitter from '~/assets/svg/twitter.svg';
import Instagram from '~/assets/svg/instagram.svg';
export default {
data () {
return {
socials: [
{
id: 1,
icon: '<Facebook/>',
url: "https://www.facebook.com",
},
{
id: 2,
icon: '<Twitter/>',
url: "https://www.twitter.com",
},
{
id: 3,
icon: '<Instagram/>',
url: "https://www.instagram.com",
}
]
}
},
components: {
Facebook,
Twitter,
Instagram
}
}
</script>
<style lang="scss">
</style>
Answer the question
In order to leave comments, you need to log in
Where did you get the idea that these are components? Most likely there is either svg code or svg file URL.
Therefore, all you need is:
socials: [
{
id: 1,
icon: Facebook,
url: "https://www.facebook.com",
},
{
id: 2,
icon: Twitter,
url: "https://www.twitter.com",
},
{
id: 3,
icon: Instagram,
url: "https://www.instagram.com",
}
]
Everything worked. Thanks for support.
The problem was that the icons did not have a height and width, I corrected them and now they are displayed normally.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question