I'm trying to generate an array of Vue Components based on a config file I have of the different UI sections to show;
const config = [
'summarySection',
'scoreSection',
'educationSection'
]
So somehow I'm trying to map this into an array of vue components that I can use in my template. I was thinking about doing something like this;
const availableComponents = {
'summarySection': <summary-section/ >,
'scoreSection': <score-section/>,
...
}
const sections = config.map((section) => availableComponents[section])
<template v-for="section in sections">
{{ section }}
</template>
But this clearly doesn't work :/. Any suggestions?
SOLUTION
Here's how I solved this;
// In my config file;
const sections = [
'profile-summary-section',
'matchbars-section',
'job-experience-section',
'education-section',
'skills-section',
'about-section',
'availability-section',
'recruiter-notes-section',
'transport-section',
]
// In my template;
<template v-for="section in sections">
<component :is="section" :key="section" v-bind="sectionProps[section]"></component>
</template>
// In my computed variables;
sectionProps() {
return {
'profile-summary-section': {
vIf: this.showSummary,
class: 'mb-2 has-light-border bg-white',
profile: this.profile,
number: 0,
showMatchPercentage: false,
},
'matchbars-section': {
...
},
};
},