Created
September 27, 2016 08:41
-
-
Save ChadTaljaardt/41c9de5f6aca54c08d5c566c67e910f9 to your computer and use it in GitHub Desktop.
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
<style> | |
</style> | |
<template> | |
<li> | |
<div :class="{bold: isFolder}" @click="toggle" @dblclick="changeType"> | |
{{model.name}} | |
<span v-if="isFolder">[{{open ? '-' : '+'}}]</span> | |
</div> | |
<ul v-show="open" v-if="isFolder"> | |
<item | |
class="item" v-for="model in model.children" :model="model"> | |
</item> | |
<li @click="addChild">+</li> | |
</ul> | |
</li> | |
</template> | |
<script> | |
export default { | |
props: { | |
model: Object | |
}, | |
data: function () { | |
return { | |
open: false | |
} | |
}, | |
computed: { | |
isFolder: function () { | |
return this.model.children && | |
this.model.children.length | |
} | |
}, | |
methods: { | |
toggle: function () { | |
if (this.isFolder) { | |
this.open = !this.open | |
} | |
}, | |
changeType: function () { | |
if (!this.isFolder) { | |
Vue.set(this.model, 'children', []) | |
this.addChild() | |
this.open = true | |
} | |
}, | |
addChild: function () { | |
this.model.children.push({ | |
name: 'new stuff' | |
}) | |
} | |
} | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment