del删除上一行的时候,下一行如果有内容会自动展开,为什么,大家帮忙解决一下,感谢!!!以下是全部的代码<!DOCTYPE html><html><head> <meta charset="UTF-8"> <title>树形视图扩展</title> <style> body { font-family: Menlo, Consolas, monospace; color: #444; } .item { cursor: pointer; } .bold { font-weight: bold; } ul { padding-left: 1em; line-height: 1.5em; list-style-type: dot; } </style> <script src="https://cdn.bootcss.com/vue/2.4.2/vue.min.js"></script></head><body><script type="text/x-template" id="item-template"> <li> <div :class="{bold: isFolder}" @click="toggle" @dblclick="changeType"> {{ model.name }} <span v-if="isFolder">[{{ open ? '-' : '+' }}]</span> <span class="bold" @click="$emit('del', index)">[del]</span> </div> <ul v-if="isFolder" v-show="open"> <item class="item" v-for="(item, index) in model.children" :key="index" :index="index" :model="item" @del="model.children.splice($event, 1)"></item> <li class="add" @click="addChild">+</li> </ul> </li></script><p>树形结构</p><ul id="demo"> <item class="item" v-for="(model, index) in treeData" :key="index" :index="index" :model="model" @del="treeData.splice($event, 1)"></item></ul><script> var data = [ {name: 'han'}, {name: 'wang'}, { name: 'liu', children: [ {name: 'zhang'}, {name: 'lu'} ] } ]; Vue.component('item', { template: '#item-template', props: { model: Object, index: Number }, data: function () { return { open: false } }, computed: { isFolder: function () { return this.model.children && this.model.children.length; } },
添加回答
举报
0/150
提交
取消