vue tree树结构以select格式展示
1、添加依赖
npm install --save @riophae/vue-treeselect
示例代码
<template> <div id="app"> <treeselect v-model="value" :multiple="true" :options="options" /> </div> </template> <script> // import the component import Treeselect from '@riophae/vue-treeselect' // import the styles import '@riophae/vue-treeselect/dist/vue-treeselect.css' export default { // register the component components: { Treeselect }, data() { return { // define the default value value: null, // define options options: [ { id: 'a', label: 'a', children: [ { id: 'aa', label: 'aa', }, { id: 'ab', label: 'ab', } ], }, { id: 'b', label: 'b', }, { id: 'c', label: 'c', } ], } }, } </script>
只允许选择子节点数据:
:disable-branch-nodes="true"
不被遮挡:
:appendToBody="true"
获取label数据:
@select="se" se(val){ val.label; },
选择框限制展示条数
:limit="1"