<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>表单提交</title>
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
<link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
<!-- 引入组件库 -->
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<style>
</style>
</head>
<body>
<div id="app">
<el-button @click="handle()">按 钮</el-button>
<el-tree :data="dataList" :props="defaultProps" @node-click="nodeClick"></el-tree>
</div>
<script type="text/javascript">
new Vue({
el: '#app',
data: {
dataList: [{
label: '一级 1',
children: [{
label: '二级 1-1',
children: [{
label: '三级 1-1-1',
children: []
}]
}]
}, {
label: '一级 2',
children: [{
label: '二级 2-1',
children: [{
label: '三级 2-1-1',
children: []
}]
}, {
label: '二级 2-2',
children: [{
label: '三级 2-2-1',
children: []
}]
}]
}, {
label: '一级 3',
children: [{
label: '二级 3-1',
children: [{
label: '三级 3-1-1',
children: []
}]
}, {
label: '二级 3-2',
children: [{
label: '三级 3-2-1',
children: []
}]
}]
}],
defaultProps: {
children: 'children',
label: 'label'
},
arr: ['一级 1', '二级 1-1', '三级 1-1-1'],
arrIndex: [],
num: 0,
node: {},
obj: {}
},
computed: {},
methods: {
nodeClick(obj, node, e) {
this.obj = obj;
this.node = node
console.log(obj, node, e);
},
handle() {
console.log(this.node);
this.node.data.children.unshift({
label: '新增文件夹',
children: []
})
// this.obj.children.unshift({
// label: '新增文件夹',
// children: []
// })
},
}
})
</script>
</body>
</html>
复制代码即可更新!