Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Recursive nested list Vue component
<template>
<span>
<ol v-if="Array.isArray(value)">
<li v-for="(item, index) in value" :key="index">
<Nested :value="item" />
</li>
</ol>
<ul v-else-if="typeof value == 'object' && !!value">
<li v-for="(val, name) in value" :key="name">
{{ name }}:
<Nested :value="val" />
</li>
</ul>
<span v-else>{{ value }}</span>
</span>
</template>
<script>
export default {
name: "Nested",
props: ["value"]
};
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment