console
var Main = {
data() {
return {
gridOptions: {
border: true,
columns: [
{ type: 'seq', width: 100, treeNode: true },
{ field: 'name', title: 'Name' },
{ field: 'sex', title: 'Sex' },
{ field: 'date', title: 'Date' },
{ field: 'address', title: 'Address' }
],
data: [],
treeConfig: { rowField: "id", expandAll: true, children: 'children' },
rowConfig: { keyField: 'id', isCurrent: true, isHover: true },
seqConfig:{seqMethod:({ row, rowIndex, column, columnIndex }) => {
return row.nodeId
}}
},
rootNode: {
id: "root",
nodeId:"1",
name: "根节点",
parent: null,
children: []
}
}
},
methods: {
addChild() {
console.info("根节点222", this.rootNode);
let p=this.rootNode.children[0];
p.children.push({
id: "dync",
nodeId:"1.1.1",
name: "动态子节点",
})
},
},
mounted() {
var list2 = []
let dir1 = {
id: "dir1",
nodeId:"1.1",
name: "子目录一",
children: []
}
let dir2 = {
id: "dir2",
nodeId:"1.2",
name: "子目录二",
children: []
}
this.rootNode.children.push(dir1);
this.rootNode.children.push(dir2);
list2.push(this.rootNode)
this.gridOptions.data = list2
}
};
Vue.createApp(Main).use(VXETable).mount('#app')
<script src="https://cdn.jsdelivr.net/npm/vue@next"></script>
<script src="https://cdn.jsdelivr.net/npm/xe-utils"></script>
<script src="https://cdn.jsdelivr.net/npm/vxe-table@next"></script>
<div id="app">
<div>
<p>Grid 演示:
<input type="button" value="添加子节点" @click="addChild"/>
</p>
<vxe-grid ref="mygrid" v-bind="gridOptions"></vxe-grid>
</div>
</div>
@import url("https://cdn.jsdelivr.net/npm/vxe-table@next/lib/style.css");