Greetings fellow developers!
Using Vue 3, composition API with setup.
I am working on a custom component "Table" to render... a table. It expects a prop called "data", which is an array of objects (as rows) with such params: title, data and a render() function. Now with render() I want to have an ability to render a custom HTML inside any of the columns if needed, like showing multiple data, custom text, custom components etc. And custom components is where I got stuck.
What I have now.
Inside Table component I have a <tr v-for>
which goes over the props.data and renders the columns. If it sees a render() function, it passes row data to that render() function, which should render the data. Render() function example:
render(row) => {
return `This is some random text and: <my-custom-component>${row.someData}</my-custom-component`;
}
And here is part of Table component:
<tr v-for="group in tableData">
<template v-for="column in props.columns">
<td v-if="column.render">
*** here I want to render whats inside render() function, including custom component ***
</td>
<td v-else :style="{ width: column.width ?? 'auto' }" v-html="group[column.data]"></td>
</template>
</tr>
This part does not work. I receive a Vue warning "Failed to resolve component". I also tried to use Vue dynamic component:
<component is="myCustomComponent"></component>
But then it renders pure HTML like that:
<mycustomcomponent></mycustomcomponent>
I tried searching for answers, but I dont think I found one. I saw many examples with using h() function, but I cant find a way to add it to my code.
It should also be noted that I am loading the data into the table after I receive it from the API.
So what am I missing? Is this even possible? I am pretty new to Vue, so very likely that I am not familiar with some concept.