b11c38453b61c985458e91127bd397c0d66f8d104348ec712b0c0a0c0dbd965587342635b1517a94ff02e29d60b55283bb9209c2ed17abeed1d2beffac1a78-exec 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. # vue-treeselect
  2. [![npm](https://badgen.now.sh/npm/v/@riophae/vue-treeselect)](https://www.npmjs.com/package/@riophae/vue-treeselect) [![Build](https://badgen.now.sh/circleci/github/riophae/vue-treeselect)](https://circleci.com/gh/riophae/vue-treeselect/tree/master) [![Coverage](https://badgen.net/codecov/c/github/riophae/vue-treeselect)](https://codecov.io/gh/riophae/vue-treeselect?branch=master)
  3. ![npm monthly downloads](https://badgen.now.sh/npm/dm/@riophae/vue-treeselect)
  4. ![jsDelivr monthly hits](https://badgen.net/jsdelivr/hits/npm/@riophae/vue-treeselect) [![Known vulnerabilities](https://snyk.io/test/npm/@riophae/vue-treeselect/badge.svg)](https://snyk.io/test/npm/@riophae/vue-treeselect) ![License](https://badgen.net/github/license/riophae/vue-treeselect)
  5. > A multi-select component with nested options support for Vue.js
  6. ![Vue-Treeselect Screenshot](https://raw.githubusercontent.com/riophae/vue-treeselect/master/screenshot.png)
  7. ### Features
  8. - Single & multiple select with nested options support
  9. - Fuzzy matching
  10. - Async searching
  11. - Delayed loading (load data of deep level options only when needed)
  12. - Keyboard support (navigate using <kbd>Arrow Up</kbd> & <kbd>Arrow Down</kbd> keys, select option using <kbd>Enter</kbd> key, etc.)
  13. - Rich options & highly customizable
  14. - Supports a wide range of browsers (see [below](#browser-compatibility))
  15. - RTL support
  16. *Requires Vue 2.2+*
  17. ### Getting Started
  18. It's recommended to install vue-treeselect via npm, and build your app using a bundler like [webpack](https://webpack.js.org/).
  19. ```bash
  20. npm install --save @riophae/vue-treeselect
  21. ```
  22. This example shows how to integrate vue-treeselect with your [Vue SFCs](https://vuejs.org/v2/guide/single-file-components.html).
  23. ```vue
  24. <!-- Vue SFC -->
  25. <template>
  26. <div id="app">
  27. <treeselect v-model="value" :multiple="true" :options="options" />
  28. </div>
  29. </template>
  30. <script>
  31. // import the component
  32. import Treeselect from '@riophae/vue-treeselect'
  33. // import the styles
  34. import '@riophae/vue-treeselect/dist/vue-treeselect.css'
  35. export default {
  36. // register the component
  37. components: { Treeselect },
  38. data() {
  39. return {
  40. // define the default value
  41. value: null,
  42. // define options
  43. options: [ {
  44. id: 'a',
  45. label: 'a',
  46. children: [ {
  47. id: 'aa',
  48. label: 'aa',
  49. }, {
  50. id: 'ab',
  51. label: 'ab',
  52. } ],
  53. }, {
  54. id: 'b',
  55. label: 'b',
  56. }, {
  57. id: 'c',
  58. label: 'c',
  59. } ],
  60. }
  61. },
  62. }
  63. </script>
  64. ```
  65. If you just don't want to use webpack or any other bundlers, you can simply include the standalone UMD build in your page. In this way, make sure Vue as a dependency is included before vue-treeselect.
  66. ```html
  67. <html>
  68. <head>
  69. <!-- include Vue 2.x -->
  70. <script src="https://cdn.jsdelivr.net/npm/vue@^2"></script>
  71. <!-- include vue-treeselect & its styles. you can change the version tag to better suit your needs. -->
  72. <script src="https://cdn.jsdelivr.net/npm/@riophae/vue-treeselect@^0.4.0/dist/vue-treeselect.umd.min.js"></script>
  73. <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@riophae/vue-treeselect@^0.4.0/dist/vue-treeselect.min.css">
  74. </head>
  75. <body>
  76. <div id="app">
  77. <treeselect v-model="value" :multiple="true" :options="options" />
  78. </div>
  79. </body>
  80. <script>
  81. // register the component
  82. Vue.component('treeselect', VueTreeselect.Treeselect)
  83. new Vue({
  84. el: '#app',
  85. data: {
  86. // define the default value
  87. value: null,
  88. // define options
  89. options: [ {
  90. id: 'a',
  91. label: 'a',
  92. children: [ {
  93. id: 'aa',
  94. label: 'aa',
  95. }, {
  96. id: 'ab',
  97. label: 'ab',
  98. } ],
  99. }, {
  100. id: 'b',
  101. label: 'b',
  102. }, {
  103. id: 'c',
  104. label: 'c',
  105. } ],
  106. },
  107. })
  108. </script>
  109. </html>
  110. ```
  111. ### Documentation & Live Demo
  112. [Visit the website](https://vue-treeselect.js.org/)
  113. Note: please use a desktop browser since the website hasn't been optimized for mobile devices.
  114. ### Browser Compatibility
  115. - Chrome
  116. - Edge
  117. - Firefox
  118. - IE ≥ 9
  119. - Safari
  120. It should function well on IE9, but the style can be slightly broken due to the lack of support of some relatively new CSS features, such as `transition` and `animation`. Nevertheless it should look 90% same as on modern browsers.
  121. ### Bugs
  122. You can use this [pen](https://codepen.io/riophae/pen/MExgzP) to reproduce bugs and then [open an issue](https://github.com/riophae/vue-treeselect/issues/new).
  123. ### Contributing
  124. 1. Fork & clone the repo
  125. 2. Install dependencies by `yarn` or `npm install`
  126. 3. Check out a new branch
  127. 4. `npm run dev` & hack
  128. 5. Make sure `npm test` passes
  129. 6. Push your changes & file a pull request
  130. ### Credits
  131. This project is inspired by [vue-multiselect](https://github.com/monterail/vue-multiselect), [react-select](https://github.com/JedWatson/react-select) and [Ant Design](https://github.com/ant-design/ant-design/). Special thanks go to their respective authors!
  132. Some icons used in this project:
  133. - "link" icon made by [Smashicons](https://www.flaticon.com/authors/smashicons) is licensed under [CC 3.0 BY](https://creativecommons.org/licenses/by/3.0/)
  134. - "spinner" icon from [SpinKit](https://github.com/tobiasahlin/SpinKit) is licensed under the [MIT License](https://github.com/tobiasahlin/SpinKit/blob/master/LICENSE)
  135. - "caret" icon made by [Dave Gandy](https://www.flaticon.com/authors/dave-gandy) is licensed under [CC 3.0 BY](https://creativecommons.org/licenses/by/3.0/)
  136. - "delete" icon made by [Freepik](https://www.flaticon.com/authors/freepik) is licensed under [CC 3.0 BY](https://creativecommons.org/licenses/by/3.0/)
  137. - "checkmark symbol" & "minus symbol" icons made by [Catalin Fertu](https://www.flaticon.com/authors/catalin-fertu) are licensed under [CC 3.0 BY](https://creativecommons.org/licenses/by/3.0/)
  138. ### License
  139. Copyright (c) 2017-present [Riophae Lee](https://github.com/riophae).
  140. Released under the [MIT License](https://github.com/riophae/vue-treeselect/blob/master/LICENSE).