Currently, I am utilizing the Material design Icons library specifically made for Vue.js. In this library, each icon is a standalone file component within its designated folder.
Within my project, I have a separate component called ToolbarButton, which includes a prop named Icon. What I aim to achieve is importing a component with a name that matches the passed prop.
Below is a snippet of my code:
<template>
<button>
<MyIcon></MyIcon>
</button>
</template>
<script>
import MyIcon from `icons/${icon}.vue`
export default {
name: 'ToolbarButton',
props: ['icon'],
components: {
MyIcon
}
}
</script>
Unfortunately, this code results in a Parsing error: Unexpected token `. Even when using 'icons/' + icon + '.vue', the issue persists. Have I missed something? I have spent significant time looking for a solution but to no avail.
One suggestion I received was to import all of the components, as the unused ones will be eliminated during compilation. However, this doesn't feel like the most efficient approach. Are there any other suggestions or solutions that I could explore?