Created
October 5, 2019 14:08
-
-
Save mdlincoln/d06d1e60c21a05486c93a8b20fe04e9c to your computer and use it in GitHub Desktop.
Recursive nested list Vue component
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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