Ai
1 Star 0 Fork 0

落木沙/vuecomp

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Tree.vue 1.89 KB
一键复制 编辑 原始数据 按行查看 历史
落木沙 提交于 2016-11-09 11:05 +08:00 . 树型目录展示
<!-- 注释 -->
<!-- 目前两个属性,一个model,用来绑定数据。另一个editable。控制是否可编辑 -->
<!--model属性绑定:{name:'root',children:[{name:'',children:[]},{name:'',children:[]}]-->
<template>
<div>
<li>
<div
:class="[{'folder':isFolder, 'glyphicon':isFolder,'test':isFolder}, isFolder?open ? 'glyphicon-folder-open' : 'glyphicon-folder-close':'']"
@click="toggle" @dblclick="changeType">
{{model.name}}
</div>
<ul v-show="open" v-if="isFolder">
<item class="item" v-for="model in model.children" :model="model"></item>
<li v-if="editable" class="add" @click="addChild">+</li>
</ul>
</li>
</div>
</template>
<script>
import Vue from 'vue'
// define the item component
export default{
name: 'item',
props: {
model: Object,
editable: false
},
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.editable) {
return
}
if (!this.isFolder) {
Vue.set(this.model, 'children', [])
this.addChild()
this.open = true
}
},
addChild: function () {
this.model.children.push({
name: 'new stuff'
})
}
}
}
</script>
<style>
body {
font-family: Menlo, Consolas, monospace;
color: #444;
}
.item {
cursor: pointer;
}
.folder {
font-weight: bold;
}
/* .folder:before {
}*/
li {
list-style-type: none;
}
ul {
/*padding-left: 1.5em;*/
/*line-height: 1.5em;*/
/*list-style-type: dot;*/
}
</style>
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/luomusha/vuecomp.git
git@gitee.com:luomusha/vuecomp.git
luomusha
vuecomp
vuecomp
master

搜索帮助