Vue2实用组件集

文章目录


Vue3使用教程请前往: Vue3实用组件集

一、vue2-perfect-scrollbar

1、介绍

Vue.js 简约但功能强大的完美滚动条包装器

2、功能

优化滚动条显示

3、安装

npm install vue2-perfect-scrollbar

4、使用

1)全局注册

import PerfectScrollbar from 'vue2-perfect-scrollbar'
import 'vue2-perfect-scrollbar/dist/vue2-perfect-scrollbar.css'

Vue.use(PerfectScrollbar)

2)代码中使用

<perfect-scrollbar>
    内容
</perfect-scrollbar>

该插件会生成一个类名为“.ps”的容器,需要自定义容器的高度

.ps {
   
  height: 400px;
}

3)例子

<template>
  <div>
    <perfect-scrollbar>
      <p v-for="item in 10">{
  { item }}</p>
    </perfect-scrollbar>
  </div>
</template>

<script>
export default {
  name: "index",
};
</script>

<style>
.ps {
  height: 200px;
}
</style>

4)效果

在这里插入图片描述

5、options配置项:以下均为默认值

options: {
   
        // 滚动元素的处理程序列表
        handlers: ['click-rail', 'drag-thumb', 'keyboard', 'wheel', 'touch'],
        // 应用于鼠标滚轮事件的滚动速度
        wheelSpeed: 1,
        // 如果此选项为真,当滚动到达边的末端时,鼠标滚轮事件将传播到父元素
        wheelPropagation: true,
        // 如果此选项为真,则滑动滚动将变得轻松
        swipeEasing: true,
        // 当设置为整数值时,滚动条的拇指部分不会缩小到低于该像素数
        minScrollbarLength: null,
        // 当设置为整数值时,滚动条的拇指部分不会扩展超过该像素数
        maxScrollbarLength: null,
        // 这集的阈值ps--scrolling-x和ps--scrolling-y类来保持。在默认 CSS 中,无论悬停状态如何,它们都会显示滚动条。单位是毫秒
        scrollingThreshold: 1000,
        // 当设置为 true,并且只有一个(垂直或水平)滚动条可见时,垂直和水平滚动都会影响滚动条
        useBothWheelAxes: false,
        // 设置为 true 时,无论内容宽度如何,X 轴上的滚动条都将不可用
        suppressScrollX: false,
        // 设置为 true 时,无论内容高度如何,Y 轴的滚动条都将不可用
        suppressScrollY: false,
        // 在不启用 X 轴滚动条的情况下,内容宽度可以超过容器宽度的像素数。允许一些“摆动空间”或“偏移中断”,这样 X 轴滚动条就不会因为几个像素而启用
        scrollXMarginOffset: 0,
        // 内容高度在不启用Y轴滚动条的情况下可以超过容器高度的像素数。允许一些“摆动空间”或“偏移中断”,这样 Y 轴滚动条就不会因为几个像素而启用
        scrollYMarginOffset: 0,
      }

6、事件

1)当 y 轴向任一方向滚动时会触发此事件

ps-scroll-y

2)当 x 轴沿任一方向滚动时会触发此事件

ps-scroll-x

3)向上滚动时会触发此事件

ps-scroll-up

4)向下滚动时会触发此事件

ps-scroll-down

5)向左滚动时会触发此事件

ps-scroll-left

6)向右滚动时会触发此事件

ps-scroll-right

7)当滚动到达 y 轴的起点时触发此事件

ps-y-reach-start

8)当滚动到达 y 轴的末端时触发此事件(对于无限滚动很有用)

ps-y-reach-end

9)当滚动到达 x 轴的起点时触发此事件

ps-x-reach-start

10)当滚动到达 x 轴的末端时会触发此事件

ps-x-reach-end

7、样式修改

滚动条的滑块和轨道的颜色可以用简单的CSS自定义。使用描述要编辑的滚动条元素的类:

/*
* Y轴轨道样式
*/
.ps__rail-y {
   
  background-color: lightgreen !important;
}
/*
* Y轴滑块样式
*/
.ps__thumb-y {
   
  background-color: darkgreen !important;
}
/*
* X轴轨道样式
*/
.ps__rail-x {
   
  background-color: lightgreen !important;
}
/*
* X轴滑块样式
*/
.ps__thumb-x {
   
  background-color: darkgreen !important;
}

工具库

Lodash

1、安装

  • 浏览器环境
<script src="lodash.js"></script>
  • 通过 npm
npm i --save lodash

2、为什么选择 Lodash

Lodash 通过降低 array、number、objects、string 等等的使用难度从而让 JavaScript 变得更简单。 Lodash 的模块化方法 非常适用于:

  • 遍历 array、object 和 string
  • 对值进行操作和检测
  • 创建符合功能的函数

Dayjs.js

1、介绍

Day.js是一个极简的JavaScript库,可以为现代浏览器解析、验证、操作和显示日期和时间。

2、安装

2.1、Node.js
  • npm安装
npm install dayjs
  • cnpm安装
cnpm install dayjs -S
  • yarn安装
yarn add dayjs
  • pnpm安装
pnpm add dayjs

使用

var dayjs = require('dayjs')
// import dayjs from 'dayjs' // ES 2015
dayjs().format()
2.2、浏览器
<script src="https://cdn.jsdelivr.net/npm/dayjs/dayjs.min.js"></script>
<script>
  dayjs().format()
</script>
2.3、微信小程序
下载 dayjs.min.js

下载 dayjs.min.js放到小程序 lib 目录下(没有新建或用其他目录)

引用示例

const dayjs = require('../../libs/dayjs.min.js');
使用 npm 安装
npm install dayjs --save

引用示例

const dayjs = require("dayjs");
Element-plus

Element-plus (opens new window)组件库默认支持 dayjs 进行日期时间处理,所以可以直接导入使用,相关 Date Picker (opens new window)组件介绍。

import {
    dayjs } from 'element-plus'

// 扩展插件
import isSameOrBefore from 'dayjs/plugin/isSameOrBefore'
import isSameOrAfter from 'dayjs/plugin/isSameOrAfter'
dayjs.extend(isSameOrBefore)
dayjs.extend(isSameOrAfter)

dayjs().isSameOrBefore(dayjs('2011-01-01'))

Intro.js 相同Driver.js

1、介绍

Intro.js 是一个开源普通 Javascript / CSS 库,用于添加分步介绍或提示。

2、安装

使用npm

npm install intro.js --save

使用yarn

yarn add intro.js

3、使用

// 引入
import introJs from 'intro.js' // introjs库
import 'intro.js/introjs.css' // introjs默认css样式
import 'intro.js/themes/introjs-modern.css' // introjs主题

// 使用
const introJsOption = {
   
  prevLabel: "上一步",
  nextLabel: "下一步",
  skipLabel: "✕",
  doneLabel: 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
Vue时间显示组件是一种用于在页面上显示时间的组件,可以用于显示升级日志、倒计时、秒表等功能。其实现原理主要是将主要区域分为两块,时间区和内容区。时间区包括画一个圆点和显示一个时间,而内容区则包括一个竖线和文字显示。通过循环将每个日期的数据显示出来,并采用flex布局来布局组件。 在Vue中,可以引入相应的组件,然后设置对应的参数,如类型、格式、时间长度等,来实现不同样式的时钟显示。这样,我们就可以根据不同需求,使用Vue时间显示组件来展示各种样式的时钟功能。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [Vue时间轴组件.zip](https://download.csdn.net/download/gdgztt/87585634)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* *3* [VUE3实用组件开发合集二:时钟、倒计时组件](https://blog.csdn.net/m0_37631110/article/details/125706576)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

向山海出发

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值