I have a component (IconInline.html
), within which I would like to import and render components dynamically based on a prop (IconID
) passed to it.
Currently I do it manually like this:
{{#if IconID === "A"}}
<A />
{{elseif IconID === "B"}}
<B />
{{elseif IconID === "C"}}
<C />
{{elseif IconID === "D"}}
<D />
{{/if}}
<script>
import A from "./icons/A.html";
import B from "./icons/B.html";
import C from "./icons/C.html";
import D from "./icons/D.html";
export default {
components: { A, B, C, D }
};
</script>
Is there a way to
- Import all components in a given directory dynamically?
- Render a specific component that matches a given prop?