@@ -685,63 +713,92 @@ Tree nodes can be initially expanded or checked
### Custom node content
The content of tree nodes can be customized, so you can add icons or buttons as you will
:::demo Use `render-content` to assign a render function that returns the content of tree nodes. See Vue's documentation for a detailed introduction of render functions. Note that this demo can't run in jsfiddle because it doesn't support JSX syntax. In a real project, `render-content` will work if relevant dependencies are correctly configured.
:::demo There are two ways to customize template for tree nodes: `render-content` and scoped slot. Use `render-content` to assign a render function that returns the content of tree nodes. See Vue's documentation for a detailed introduction of render functions. If you prefer scoped slot, you'll have access to `node` and `data` in the scope, standing for the TreeNode object and node data of the current node respectively. Note that the `render-content` demo can't run in jsfiddle because it doesn't support JSX syntax. In a real project, `render-content` will work if relevant dependencies are correctly configured.
```html
<el-tree
:data="data4"
:props="defaultProps"
show-checkbox
node-key="id"
default-expand-all
:expand-on-click-node="false"
:render-content="renderContent">
</el-tree>
<divclass="custom-tree-container">
<divclass="block">
<p>Using render-content</p>
<el-tree
:data="data4"
show-checkbox
node-key="id"
default-expand-all
:expand-on-click-node="false"
:render-content="renderContent">
</el-tree>
</div>
<divclass="block">
<p>Using scoped slot</p>
<el-tree
:data="data5"
show-checkbox
node-key="id"
default-expand-all
:expand-on-click-node="false">
<spanclass="custom-tree-node"slot-scope="{ node, data }">
<span>{{ node.label }}</span>
<span>
<el-button
type="text"
size="mini"
@click="() => append(data)">
Append
</el-button>
<el-button
type="text"
size="mini"
@click="() => remove(node, data)">
Delete
</el-button>
</span>
</span>
</el-tree>
</div>
</div>
<script>
letid=1000;
exportdefault{
data(){
return{
data4:[{
id:1,
label:'Level one 1',
children:[{
id:4,
label:'Level two 1-1',
children:[{
id:9,
label:'Level three 1-1-1'
},{
id:10,
label:'Level three 1-1-2'
}]
}]
},{
id:2,
label:'Level one 2',
constdata=[{
id:1,
label:'Level one 1',
children:[{
id:4,
label:'Level two 1-1',
children:[{
id:5,
label:'Level two 2-1'
id:9,
label:'Level three 1-1-1'
},{
id:6,
label:'Level two 2-2'
id:10,
label:'Level three 1-1-2'
}]
}]
},{
id:2,
label:'Level one 2',
children:[{
id:5,
label:'Level two 2-1'
},{
id:3,
label:'Level one 3',
children:[{
id:7,
label:'Level two 3-1'
},{
id:8,
label:'Level two 3-2'
}]
}],
defaultProps:{
children:'children',
label:'label'
}
id:6,
label:'Level two 2-2'
}]
},{
id:3,
label:'Level one 3',
children:[{
id:7,
label:'Level two 3-1'
},{
id:8,
label:'Level two 3-2'
}]
}];
return{
data4:JSON.parse(JSON.stringify(data)),
data5:JSON.parse(JSON.stringify(data))
}
},
...
...
@@ -763,19 +820,28 @@ The content of tree nodes can be customized, so you can add icons or buttons as
@@ -986,3 +1052,8 @@ Only one node among the same level can be expanded at one time.
| current-change | triggers when current node changes | two parameters: node object corresponding to the current node, `node` property of TreeNode |
| node-expand | triggers when current node open | three parameters: node object corresponding to the node opened, `node` property of TreeNode, TreeNode itself |
| node-collapse | triggers when current node close | three parameters: node object corresponding to the node closed, `node` property of TreeNode, TreeNode itself |
### Scoped slot
| name | Description |
|------|--------|
| — | Custom content for tree nodes. The scope parameter is { node, data } |
@@ -685,63 +713,92 @@ Los nodos pueden estar desplegados o seleccionados por defecto.
### Contenido personalizado en los nodos
El contenido de los nodos puede ser personalizado, así que puede añadir iconos y botones a su gusto.
:::demo Utilice `render-content` para asignar una función de renderizado que devuelve el contenido del árbol de nodos. Mire la documentación de node para una introducción detallada a las funciondes de renderizado. Ten en cuenta que este ejemplo no puede ejecutarse en jsfiddle ya que no soporta la sintaxis JSX. En un proyecto real `render-content` funcionará si las dependencias relevantes están configuradas correctamente.
:::demo There are two ways to customize template for tree nodes: `render-content` and scoped slot. Utilice `render-content` para asignar una función de renderizado que devuelve el contenido del árbol de nodos. Mire la documentación de node para una introducción detallada a las funciondes de renderizado. If you prefer scoped slot, you'll have access to `node` and `data` in the scope, standing for the TreeNode object and node data of the current node respectively. Ten en cuenta que este ejemplo no puede ejecutarse en jsfiddle ya que no soporta la sintaxis JSX. En un proyecto real `render-content` funcionará si las dependencias relevantes están configuradas correctamente.
```html
<el-tree
:data="data4"
:props="defaultProps"
show-checkbox
node-key="id"
default-expand-all
:expand-on-click-node="false"
:render-content="renderContent">
</el-tree>
<divclass="custom-tree-container">
<divclass="block">
<p>Using render-content</p>
<el-tree
:data="data4"
show-checkbox
node-key="id"
default-expand-all
:expand-on-click-node="false"
:render-content="renderContent">
</el-tree>
</div>
<divclass="block">
<p>Using scoped slot</p>
<el-tree
:data="data5"
show-checkbox
node-key="id"
default-expand-all
:expand-on-click-node="false">
<spanclass="custom-tree-node"slot-scope="{ node, data }">
<span>{{ node.label }}</span>
<span>
<el-button
type="text"
size="mini"
@click="() => append(data)">
Append
</el-button>
<el-button
type="text"
size="mini"
@click="() => remove(node, data)">
Delete
</el-button>
</span>
</span>
</el-tree>
</div>
</div>
<script>
letid=1000;
exportdefault{
data(){
return{
data4:[{
id:1,
label:'Level one 1',
children:[{
id:4,
label:'Level two 1-1',
children:[{
id:9,
label:'Level three 1-1-1'
},{
id:10,
label:'Level three 1-1-2'
}]
}]
},{
id:2,
label:'Level one 2',
constdata=[{
id:1,
label:'Level one 1',
children:[{
id:4,
label:'Level two 1-1',
children:[{
id:5,
label:'Level two 2-1'
id:9,
label:'Level three 1-1-1'
},{
id:6,
label:'Level two 2-2'
id:10,
label:'Level three 1-1-2'
}]
}]
},{
id:2,
label:'Level one 2',
children:[{
id:5,
label:'Level two 2-1'
},{
id:3,
label:'Level one 3',
children:[{
id:7,
label:'Level two 3-1'
},{
id:8,
label:'Level two 3-2'
}]
}],
defaultProps:{
children:'children',
label:'label'
}
id:6,
label:'Level two 2-2'
}]
},{
id:3,
label:'Level one 3',
children:[{
id:7,
label:'Level two 3-1'
},{
id:8,
label:'Level two 3-2'
}]
}];
return{
data4:JSON.parse(JSON.stringify(data)),
data5:JSON.parse(JSON.stringify(data))
}
},
...
...
@@ -763,19 +820,28 @@ El contenido de los nodos puede ser personalizado, así que puede añadir iconos
@@ -984,3 +1050,8 @@ Solo puede ser expandido un nodo del mismo nivel a la vez.
| current-change | cambia cuando el nodo actual cambia | dos parámetros: objeto nodo que se corresponde al nodo actual y propiedad `node` del TreeNode |
| node-expand | se lanza cuando el nodo actual se abre | tres parámetros: el objeto del nodo abierto, propiedad `node` de TreeNode y el TreeNode en si |
| node-collapse | se lanza cuando el nodo actual se cierra | tres parámetros: el objeto del nodo cerrado, propiedad `node` de TreeNode y el TreeNode en si |
### Scoped slot
| name | Description |
|------|--------|
| — | Custom content for tree nodes. The scope parameter is { node, data } |