Skip to content

Instantly share code, notes, and snippets.

@mdlincoln
Created October 5, 2019 14:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mdlincoln/d06d1e60c21a05486c93a8b20fe04e9c to your computer and use it in GitHub Desktop.
Save mdlincoln/d06d1e60c21a05486c93a8b20fe04e9c to your computer and use it in GitHub Desktop.
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