记录基于Vue.js的移动端Tree树形组件

news2024/9/28 7:22:45

目录

一、Liquor Tree

入门 :

Development

Component Options 组件选项

Structure 结构

二、vue-treeselect

Introduction 介绍

Getting Started 入门


Vue 树形选择器( Vue tree select )组件在搭建 Vue 的 app 中特别常用,Vue tree select 除了简单的树形结构外,还有非常多样的功能来配合不同场景的使用。比如搜索过滤,前端添加删除树枝,前端编辑修改子树名,拖拽排序,对用户操作事件记录等。本文记录了我自己使用多年最好用的 2 款 Vue tree select 组件,每一款都经过我实际测试,推荐给大家。


一、Liquor Tree

酒树 (Liquor Tree)

Liquor Tree 是一款轻量级树形选择器,对移动端友好,可拖放,支持键盘快捷键,每个操作动作都有事件记录,与 Vue 高度整合。Liquor Tree 代码简洁,扩展性强,可根据你的应用场景按需定制。

    A Vue tree component that allows you to present hierarchically organized data in a nice and logical manner.

    Vue 树组件,可让您以美观和逻辑的方式呈现层次结构的数据。

    supports mobile, and has a variety of response events. Flexible configuration options, and support for keyboard navigation.

    支持移动,并具有各种响应事件。 灵活的配置选项,并支持键盘导航。

View demo    查看演示    Documentation

github 地址 :

GitHub - amsik/liquor-tree: Tree component based on Vue.js

Vue 官方地址 :

Liquor Tree

Liquor-Tree

产品特点 :

  • 拖放 移动友好
  • 每个动作的事件
  • 灵活的配置
  • 每页任意数量的实例
  • 多选
  • 键盘导航
  • 过滤
  • 分类
  • 与 Vuex 集成

入门 :

安装 :

Npm:

$ npm install liquor-tree

Yarn:

$ yarn add liquor-tree

要在自己的计算机上运行该演示,请执行以下操作:

克隆此存储库

  • npm install ( npm安装 )
  • npm run build ( npm运行构建 )
  • npm run storybook
  • 访问 http://localhost:9001/

这里有很多例子供您参考。 所有来源都位于 liquor-tree/docs/storybook/stories


它必须安装到 VueJS 实例中。请查看官方文档,了解如何使用 VueJS 组件 components

(当然,如果需要的话)。
您不需要关心样式,它们会自动附加到文档中。
当与模块系统一起使用时,有三种方法可以注册组件(可能更多…我不知道)。
好了,下面这是我们的方式:

import Vue from 'vue'
import LiquorTree from 'liquor-tree'

// global registration
Vue.use(LiquorTree) // 第一种

// or
Vue.component(LiquorTree.name, LiquorTree) // 第二种

// or
import LiquorTree from 'liquor-tree'

// local registration
export default {
  name: 'your-awesome-component',
  components: {
    [LiquorTree.name]: LiquorTree // 第三种
  },
  ...
}

要注册库,您可以在我上面提到的 3 种方法之间进行选择。

当直接在浏览器中使用时,您可以通过CND包含 liquor-tree(这是库的最新版本): 

<script src="https://cdn.jsdelivr.net/npm/liquor-tree/dist/liquor-tree.umd.js"></script>

Usage 用法

  <!-- Vue Component -->
  <template>
    <tree
        :data="items"
        :options="options"
        ref="tree"
    />
  </template>

  <script>
    import Vue from 'vue'
    import LiquorTree from 'liquor-tree'

    Vue.use(LiquorTree)

    export default {
      ...
      data() {
        return {
          items: [
            {text: 'Item 1'},
            {text: 'Item 2'},
            {text: 'Item 3', children: [
              {text: 'Item 3.1'},
              {text: 'Item 3.2'}
            ]},
      {
        text: '园区其他机构',
        children: [
          {
            text: '园区其他机构1',
            children: [
              { text: '园区其他机构1.1.1' },
              { text: '园区其他机构1.1.2' },
              { text: '园区其他机构1.1.3' },
            ],
          },
          {
            text: '园区其他机构2',
            children: [
              { text: '园区其他机构2.1.1' },
              { text: '园区其他机构2.1.2' },
              { text: '园区其他机构2.1.3' },
            ],
          },
        ],
      },
          ],
          options: {
            checkbox: true
          }
        }
      }
      ...
    }
  </script>

Development

Check out the package.jsons script section. There are 2 scripts:

  • npm run dev - it will open browser and you can play with code
  • npm run build - it will craete a module file in production mode

Component Options 组件选项

Name 名称Type 类型DefaultDescription 描述
multipleBooleantrue

Allows to select more than one node.

允许选择多个节点

checkboxBooleanfalse

checkbox mode. It shows checkboxes for every node

复选框模式。它显示每个节点的复选框

checkOnSelectBooleanfalse

For checkbox mode only. Node will have checked state when user clicks either text or checkbox

仅用于复选框模式。当用户单击文本或复选框时,节点将处于选中状态

autoCheckChildrenBooleantrue

For checkbox mode only. Children will have the same checked state as their parent.

仅用于复选框模式。子级将具有与其父级相同的选中状态。

parentSelectBooleanfalse

By clicking node which has children it expands node. i.e we have two ways to expand/collapse node: by clicking on arrow and on text

通过单击具有子节点的节点,可以展开节点。即,我们有两种方法来展开/折叠节点:单击箭头和文本

keyboardNavigationBooleantrue

Allows user to navigate tree using keyboard

允许用户使用键盘浏览树

propertyNamesObject-

This options allows the default tree’s structure to be redefined. See example

此选项允许重新定义默认树的结构。见示例

deletionBoolean | Functionfalse

If keyboardNavigation is false this property is ignored. This property defines deletion behaviour. See example

如果 keyboardNavigation 为 false ,则忽略此属性。此属性定义删除行为。见示例

fetchDataObject-See guide
dndObject-See guide   请参阅指南
editingObject-See guide

Structure 结构

The component has only two props: data and options. 该组件只有两个支柱:数据和选项。

  • property options - This property defines tree behavior.   属性选项 - 此属性定义树行为
  • property data - Array-like object that defines tree nodes. 属性数据 - 定义树节点的类似数组的对象

关于 Liquor Tree 树形组件的介绍就到此为止了,因为此组件未满足业务需求:搜索过滤功能。

再加上官方文档全都是英文的,所以就懒得再继续研究下去了。

因此另辟蹊径,找到了个人认为更加友好、更加优秀的一款 Tree 树形组件。

期间查询到一款应该还不错 :LyTree 树形组件 ( 貌似无搜索过滤 )

链接 🔗 : tree树形组件 - DCloud 插件市场


二、vue-treeselect

@riophae/vue-treeselect

GitHub 地址 🔗 : GitHub - riophae/vue-treeselect: A multi-select component with nested options support for Vue.jsA multi-select component with nested options support for Vue.js - GitHub - riophae/vue-treeselect: A multi-select component with nested options support for Vue.jshttps://github.com/riophae/vue-treeselect

Vue-TreeSelect 官网 🔗 :Vue-TreeselectA multi-select component with nested options support for Vue.jshttps://vue-treeselect.js.org/

A multi-select component with nested options support for Vue.js

一个支持 Vue.js 的嵌套选项的多选组件


Introduction 介绍

vue-treeselect is a multi-select component with nested options support for Vue.js.

treeselecte 是一个具有嵌套选项的多选择组件,支持 Vue.js。

  • Single & multiple select with nested options support ( 支持嵌套选项的单个和多个选项 )
  • Fuzzy matching ( 模糊匹配 )
  • Async searching ( 异步搜索 )
  • Delayed loading ( load data of deep level options only when needed )
  • ( 支持嵌套选项的单个和多个选择 )
  • Keyboard support ( navigate using Arrow Up & Arrow Down keys, select option using Enter key, etc. ) ( 支持嵌套选项的单个和多个选择,使用回车键等 )
  • Rich options & highly customizable ( 丰富的选项和高度可定制的 )
  • Supports a wide range of browsers ( 支持多种浏览器 )

Requires Vue 2.2+ ( 必须 Vue 2.2+ )

Getting Started 入门

It's recommended to install vue-treeselect via npm, and build your app using a bundler like webpack.

建议通过 npm 安装 vue-treeselect ,并使用类似 bundler 的 webpack 构建您的应用程序。

npm install --save @riophae/vue-treeselect

This example shows how to integrate vue-treeselect with your Vue SFCs.

这个示例展示了如何将 Vue 树选择与 Vue SFC 集成。

<!-- Vue SFC -->
<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>

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.

如果你只是不想使用 webpack 或任何其他捆绑器,你可以简单地在你的页面中包括独立的UMD 构建。通过这种方式,确保在 Vue 树选择之前包含 Vue 作为依赖项。

<html>
  <head>
    <!-- include Vue 2.x -->
    <script src="https://cdn.jsdelivr.net/npm/vue@^2"></script>
    <!-- include vue-treeselect & its styles. you can change the version tag to better suit your needs. -->
    <script src="https://cdn.jsdelivr.net/npm/@riophae/vue-treeselect@^0.4.0/dist/vue-treeselect.umd.min.js"></script>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@riophae/vue-treeselect@^0.4.0/dist/vue-treeselect.min.css">
  </head>
  <body>
    <div id="app">
      <treeselect v-model="value" :multiple="true" :options="options" />
    </div>
  </body>
  <script>
    // register the component
    Vue.component('treeselect', VueTreeselect.Treeselect)

    new Vue({
      el: '#app',
      data: {
        // 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>
</html>


未完待续 。。。


推荐文章 🔗 : VueTreeselect_vue-treeselect_捡垃圾的小女孩的博客 

https://www.cnblogs.com/webSnow/p/16043117.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/637241.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

算法提高-图论- 负环

负环 负环AcWing 904. 虫洞AcWing 361. 观光奶牛AcWing 1165. 单词环 负环 本博客主要介绍spfa求负环 一般用第二种方法 第一种方法如果每个点入队n次&#xff0c;每次入队也要遍历n次&#xff0c;那么时间复杂度就是n2 第二种方法时间复杂度是n&#xff0c;只要发现最短路边数…

城市道路路面病害检测识别分析,以RDD赛事捷克-印度-日本集成融合数据集为例,基于yolov5m模型开发构建城市道路病害检测识别系统

城市道路病害检测是最近比较热门的一个任务领域&#xff0c;核心就是迁移深度学习目前已有的研究成果来实现实时城市道路路面病害的检测识别分析&#xff0c;在我之前的很多博文中都有做过类似桥梁、大坝、基建、隧道等水泥设施裂缝裂痕等目标检测相关的项目&#xff0c;除此之…

SQL Server 2008 定时自动备份和自动删除方法

SQL Server 2008 数据定时自动备份和自动删除方法&#xff0c;同一个计划兼备数据备份数数据删除的操作方法 工具/原料 SQL Server 2008 方法/步骤 1、 点击实例名下的【管理】-【维护计划】-点击鼠标右键&#xff0c;点击【维护计划向导】&#xff0c;填写计划名称&…

崛起的中国卫浴:市场与创新双驱动

5月28日&#xff0c;国产大飞机C919完美完成了商业航班首飞。从中国制造到中国创造&#xff0c;C919的成功是无数中国企业、中国品牌的缩影。 改革开放至今的短短四十年间&#xff0c;中国经历了“以市场换技术-模仿式创新-源创新”三个阶段&#xff0c;上世纪90年代&#xff…

【IMX6ULL驱动开发学习】07.注册驱动设备_分配固定的次设备号_cdev

一、register_chrdev 在之前的hello驱动中&#xff0c;注册驱动设备的方式如下 /*初始化设备方法1&#xff1a;自动分配设备号&#xff0c;占用所有次设备号*/ major register_chrdev(0,"hello_drv",&hello_fops);使用 register_chrdev 分配设备号的方式比较…

【JAVA开发环境配置】 我也可以让JDK版本来去自由的切换了! 哈哈哈哈 舒服!

&#x1f680; 个人主页 极客小俊 ✍&#x1f3fb; 作者简介&#xff1a;web开发者、设计师、技术分享博主 &#x1f40b; 希望大家多多支持一下, 我们一起进步&#xff01;&#x1f604; &#x1f3c5; 如果文章对你有帮助的话&#xff0c;欢迎评论 &#x1f4ac;点赞&#x1…

单页面控制中心 vue-router

一、 路由的基本配置 1. 在router->index.js中&#xff0c;配置一个懒路由&#xff0c;定义页面加载哪个组件 import Vue from vue import VueRouter from vue-routerVue.use(VueRouter)const routes []// 配置一个懒路由,不然会加载页面下所有组件 const router new Vu…

基于微信小程序的失物招领系统设计与实现

博主介绍&#xff1a;✌擅长Java、微信小程序、Python、Android等&#xff0c;专注于Java技术领域和毕业项目实战✌ &#x1f345;文末获取源码联系&#x1f345; &#x1f447;&#x1f3fb; 精彩专栏推荐订阅&#x1f447;&#x1f3fb; 不然下次找不到哟 Java项目精品实战案…

BI工具+方案:火速构建电商数据分析架构

电商数据分析该怎么做&#xff1f;谁都知道电商数据分析讲究效率和精细化&#xff0c;光是围绕电商销售分析&#xff0c;就需要制作包括管理驾驶舱、销售预算分析、店铺销售增长趋势、店铺排名分析、商品退货分析等近20种电商数据分析报表。怎么才能又快又好地完成智能数据分析…

java设计模式之:装饰器模式

前言 在软件设计中&#xff0c;我们也有一种类似新房装修的技术可以对已有对象&#xff08;新房&#xff09;的功能进行扩展&#xff08;装修&#xff09;&#xff0c;以获得更加符合用户需求的对象&#xff0c;使得对象具有更加强大的功能。这种技术对应于一种被称之为装饰模…

Bug序列——容器内给/root目录777权限后无法使用ssh免密登录

Linux——创建容器并将本地调试完全的前后端分离项目打包上传docker运行_北岭山脚鼠鼠的博客-CSDN博客 接着上一篇文章结尾出现403错误时通过赋予/root目录以777权限解决403错误。 chmod 777 /root 现在又出现新的问题&#xff0c;远程ssh无法免密登录了&#xff0c;即使通过…

准备了2个月,怒刷面试题,4面字节跳动,顺利拿到 offer

说到字节跳动的经历还是比较搞笑的。一开始我特别想去那个游戏测试部门&#xff0c;当然 data测试部门也是特别想去的&#xff0c;但是提前批只能投一个&#xff0c;于是投了游戏&#xff0c;结果第二天就给我挂了。。。中间北京的捞我&#xff0c;但是不想去北京所以拒绝了&am…

说透缓存击穿、穿透、雪崩及常用解决方案

文章目录 缓存击穿、穿透、雪崩及解决方案击穿、穿透、雪崩的意思缓存击穿缓存穿透缓存雪崩总结 系列文章目录 本文是系列文章&#xff0c;为了增强您的阅读体验&#xff0c;已将系列文章目录放入文章末尾。&#x1f44d;&#x1f44d;&#x1f44d; 缓存击穿、穿透、雪崩及解决…

我的内网渗透-metasploit基础

目录 MSF postgresql msf模块 永恒之蓝 木马下放 后渗透一些简单命令 MSF Msfconsole是Metasploit框架的主要控制台界面。 开源的渗透软件 postgresql 使用的是postgresql数据库&#xff08;metasploit所依载的数据库&#xff0c;没有他也可以运行metasploit框架&…

Vue中如何进行二维码生成与扫描?

Vue中如何进行二维码生成与扫描&#xff1f; 二维码是一种广泛应用于各种场合的编码方式&#xff0c;它可以将信息编码成一张二维图案&#xff0c;方便快捷地传递信息。在Vue.js中&#xff0c;我们可以使用一些库和组件来实现二维码的生成和扫描。本文将介绍如何在Vue中实现二…

高频RFID工业读写器在自动化产线上如何应用?

工业读写器在自动化生产上具有十分重要的作用&#xff0c;它可以对工业生产中的贴上RFID标签的各种零部件和产品&#xff0c;进行跟踪与识别。利用RFID技术进行非接触的物体识别和追踪&#xff0c;更好的掌握产线上的物料信息。 高频RFID工业读写器在自动化产线上如何应用&…

Android studio C++调试问题汇总

问题1&#xff1a;如下图所示&#xff0c;cpp目录不显示或cpp目录不显示C源文件。 此问题由由于abiFilter指定为armeabi&#xff0c;但armeabi架构已经不再支持的原因导致&#xff0c;将armeabi修改为armeabi-v7a或arm64等其他支持的架构即可&#xff0c;修改后如下图所示&…

致敬易语言,Excel衍生新型中文编程,Python用户:转折点到了

没有逃过被命运的捉弄 易语言作为中文编程里的老大&#xff0c;刚开始的时候&#xff0c;叫E语言。 创始人吴涛&#xff0c;地道的中国人&#xff0c;就是为了让中国人不再孜孜不倦的去追难懂的编程语言&#xff0c;降低开发门槛。 易语言的结局最终也没逃过被命运的捉弄&…

一款可以拿来做毕设的图书管理系统,简单易掌握,非常nice

项目介绍 项目简介 使用jsp、layui、mysql完成的图书馆系统&#xff0c;包含用户图书借阅、图书管理员、系统管理员界面&#xff0c;功能齐全。 项目详细介绍 本图书管理系统总体上分为前台页面显示和后台管理。 共包含三个大模块&#xff1a;用户、图书管理员、系统管理员…

全量程真空压力综合测量系统的高精度控制解决方案

摘要&#xff1a;针对工作范围在5~1.3Pa&#xff0c;控制精度在0.1%~0.5%读数的全量程真空压力综合测量系统技术要求&#xff0c;本文提出了稳压室真空压力精密控制的技术方案。为保证控制精度&#xff0c;基于动态平衡法&#xff0c;技术方案在高真空、低真空和正压三个区间内…