I’m trying to display icon when condition is passed and for that I’m using theme icon
Script Code
<script setup>
import { h } from 'vue'
const props = defineProps({
itemDetail: Object
});
const passedIcon = h('i', {class: 'bx bxs-check-circle'});
const failedIcon = h('i', {class: 'bx bxs-cross-circle'});
</script>
Template Code
<template>
<tr>
<td>Zip check</td>
<td>
{{ props.itemDetail.status == 'pass' ? 'Passed ' + passedIcon : 'Failed ' + failedIcon }}
</td>
</tr>
</template>
But It’s returning
Passed [object Object]
or
Failed [object Object]
I had tried with h() render function but passed directly through .innerHTML
which works fine but How can I achieve to directly call as html with h() render function in the template?
2
Answers
Vue SFC Playground
Convert your functional components to functions – they are called functional for a reason:
You could use the built-in component
component
with its propis
bound to the icon based on the condition :DEMO
You could also avoid repeating the conditional statement by refactoring the vnode created by
h
: