Answer the question
In order to leave comments, you need to log in
How to insert a component in vue js props?
One component looks like this
<template>
<router-link :to="href" class="tabbar-item">
<div class="icon"><component :is="icon"/></div>
<div class="view-name">{{ viewName }}</div>
</router-link>
</template>
<TabBarItem href='Home' :icon="homeIcon" viewName="Дом"></TabBarItem>
<script>
import TabBarItem from '@/components/TabBarItem'
import iconHome from '@/components/icons/iconHome'
export default {
components: {
TabBarItem,
iconHome
},
data(){
return {
homeIcon: iconHome
}
}
}
</script>
Answer the question
In order to leave comments, you need to log in
If I'm not mistaken, then a component that is not rendered does not need to be declared in the
UPD
components section
. Well, in general, it would be better to use a named slot here. Or dynamic import something like this:
<template>
<router-link :to="href" class="tabbar-item">
<div class="icon"><component :is="iconComponent"/></div>
<div class="view-name">{{ viewName }}</div>
</router-link>
</template>
<script>
export default {
props: ['iconName'],
computed () {
iconComponent() {
return import('@/components/icons/' + this.iconName)
}
}
}
</script>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question