Home > headlines > body text

10 latest and practical JS tool libraries in 2022 [Recommended]

青灯夜游
Release: 2022-01-18 14:20:27
forward
3703 people have browsed it

This article will share with you the 10 most popular practical JS tool libraries, which are used in 80% of projects. Come and collect them for use. I hope it will be helpful to everyone!

10 latest and practical JS tool libraries in 2022 [Recommended]

The important thing that distinguishes masters from ordinary people is that they are good at using tools and leave more time for planning and thinking. The same goes for writing code. If you use the tools well, you will have more time to plan the architecture and overcome difficulties. Today I will share with you the most popular js tool library currently. If you find it useful, please give it a thumbs up!

1. Day.js

A minimalist JavaScript library for processing time and date. The API design remains the same as Moment.js, but the size is only 2KB.

npm install dayjs
Copy after login

Basic usage

import dayjs from 'dayjs'

dayjs().format('YYYY-MM-DD HH:mm') // => 2022-01-03 15:06
dayjs('2022-1-3 15:06').toDate() // => Mon Jan 03 2022 15:06:00 GMT+0800 (中国标准时间)
Copy after login

2. qs

A lightweight JavaScript library for url parameter conversion

npm install qs
Copy after login

Basic usage

import qs from 'qs'

qs.parse('user=tom&age=22') // => { user: "tom", age: "22" }
qs.stringify({ user: "tom", age: "22" }) // => user=tom&age=22
Copy after login

3. js-cookie

A simple, lightweight js API for handling cookies

npm install js-cookie
Copy after login

Basic usage

import Cookies from 'js-cookie'

Cookies.set('name', 'value', { expires: 7 }) // 有效期7天
Cookies.get('name') // => 'value'
Copy after login

4. flv.js

bilibili is an open source html5 flash video player that makes the browser FLV can be played without the help of flash plug-in, which is currently the mainstream live broadcast and on-demand solution.

npm install flv.js
Copy after login

Basic usage

<video autoplay controls width="100%" height="500" id="myVideo"></video>

import flvjs from &#39;flv.js&#39;

// 页面渲染完成后执行
if (flvjs.isSupported()) {
  var myVideo = document.getElementById(&#39;myVideo&#39;)
  var flvPlayer = flvjs.createPlayer({
    type: &#39;flv&#39;,
    url: &#39;http://localhost:8080/test.flv&#39; // 视频 url 地址
  })
  flvPlayer.attachMediaElement(myVideo)
  flvPlayer.load()
  flvPlayer.play()
}
Copy after login

5. vConsole

A lightweight, scalable front-end development for mobile web pages or debug panel. If you are still struggling with how to debug code on your mobile phone, use it.

npm install vconsole
Copy after login

Basic Usage

import VConsole from &#39;vconsole&#39;

const vConsole = new VConsole()
console.log(&#39;Hello world&#39;)
Copy after login

Recently I have found that many guys only collect and don’t like. This is not a good habit. Rejecting free prostitution starts with you and me! Come move with me and give me a like first! Collect again!

6. Animate.css

A cross-browser css3 animation library with many typical css3 animations built-in, with good compatibility and easy use.

npm install animate.css
Copy after login

Basic usage

<h1 class="animate__animated animate__bounce">An animated element</h1>

import &#39;animate.css&#39;
Copy after login

7. animejs

A powerful Javascript animation library. It can work with CSS3 properties, SVG, DOM elements, and JS objects to produce various high-performance, smooth transition animation effects.

npm install animejs
Copy after login

Basic usage

<div class="ball" style="width: 50px; height: 50px; background: blue"></div>

import anime from &#39;animejs/lib/anime.es.js&#39;

// 页面渲染完成之后执行
anime({
  targets: &#39;.ball&#39;,
  translateX: 250,
  rotate: &#39;1turn&#39;,
  backgroundColor: &#39;#F00&#39;,
  duration: 800
})
Copy after login

8, lodash.js

A consistent, modular, high-performance JavaScript Practical tool library

npm install lodash
Copy after login

Basic usage

import _ from &#39;lodash&#39;

_.max([4, 2, 8, 6]) // 返回数组中的最大值 => 8
_.intersection([1, 2, 3], [2, 3, 4]) // 返回多个数组的交集 => [2, 3]
Copy after login

9, mescroll.js

An exquisite, on the H5 side The running pull-down refresh and pull-up loading plug-ins are mainly used in scenarios such as list paging and refreshing.

npm install mescroll.js
Copy after login

Basic usage (vue component)

<template>
  <div>
    <mescroll-vue
      ref="mescroll"
      :down="mescrollDown"
      :up="mescrollUp"
      @init="mescrollInit"
    >
      <!--内容...-->
    </mescroll-vue>
  </div>
</template>

<script>
import MescrollVue from &#39;mescroll.js/mescroll.vue&#39;

export default {
  components: {
    MescrollVue
  },
  data() {
    return {
      mescroll: null, // mescroll实例对象
      mescrollDown: {}, //下拉刷新的配置
      mescrollUp: {
        // 上拉加载的配置
        callback: this.upCallback
      },
      dataList: [] // 列表数据
    }
  },
  methods: {
    // 初始化的回调,可获取到mescroll对象
    mescrollInit(mescroll) {
      this.mescroll = mescroll
    },
    // 上拉回调 page = {num:1, size:10}; num:当前页 ,默认从1开始; size:每页数据条数,默认10
    upCallback(page, mescroll) {
      // 发送请求
      axios
        .get(&#39;xxxxxx&#39;, {
          params: {
            num: page.num, // 当前页码
            size: page.size // 每页长度
          }
        })
        .then(response => {
          // 请求的列表数据
          let arr = response.data
          // 如果是第一页需手动置空列表
          if (page.num === 1) this.dataList = []
          // 把请求到的数据添加到列表
          this.dataList = this.dataList.concat(arr)
          // 数据渲染成功后,隐藏下拉刷新的状态
          this.$nextTick(() => {
            mescroll.endSuccess(arr.length)
          })
        })
        .catch(e => {
          // 请求失败的回调,隐藏下拉刷新和上拉加载的状态;
          mescroll.endErr()
        })
    }
  }
}
</script>

<style scoped>
.mescroll {
  position: fixed;
  top: 44px;
  bottom: 0;
  height: auto;
}
</style>
Copy after login

10. Chart.js

A set of simple, Clean and attractive JavaScript chart library

npm install chart.js
Copy after login

Basic usage

<canvas id="myChart" width="400" height="400"></canvas>

import Chart from &#39;chart.js/auto&#39;

// 页面渲染完成后执行
const ctx = document.getElementById(&#39;myChart&#39;)
const myChart = new Chart(ctx, {
  type: &#39;bar&#39;,
  data: {
    labels: [&#39;Red&#39;, &#39;Blue&#39;, &#39;Yellow&#39;, &#39;Green&#39;, &#39;Purple&#39;, &#39;Orange&#39;],
    datasets: [
      {
        label: &#39;# of Votes&#39;,
        data: [12, 19, 3, 5, 2, 3],
        backgroundColor: [
          &#39;rgba(255, 99, 132, 0.2)&#39;,
          &#39;rgba(54, 162, 235, 0.2)&#39;,
          &#39;rgba(255, 206, 86, 0.2)&#39;,
          &#39;rgba(75, 192, 192, 0.2)&#39;,
          &#39;rgba(153, 102, 255, 0.2)&#39;,
          &#39;rgba(255, 159, 64, 0.2)&#39;
        ],
        borderColor: [
          &#39;rgba(255, 99, 132, 1)&#39;,
          &#39;rgba(54, 162, 235, 1)&#39;,
          &#39;rgba(255, 206, 86, 1)&#39;,
          &#39;rgba(75, 192, 192, 1)&#39;,
          &#39;rgba(153, 102, 255, 1)&#39;,
          &#39;rgba(255, 159, 64, 1)&#39;
        ],
        borderWidth: 1
      }
    ]
  },
  options: {
    scales: {
      y: {
        beginAtZero: true
      }
    }
  }
})
Copy after login

Each of the above tool libraries was personally tested by myself, and the current company projects are basically in use. If you have any questions, please share them in the comment area. If you have other good tools, please share them. Let’s improve work efficiency together and defeat all evil capitalism

Finally, don’t forget to like it! Wish you riches in 2022! Gorgeous! Extremely thin!

Original address: https://juejin.cn/post/7048963605462515743

Author: Front-end A Fei

[Related recommendations: javascript Study tutorial

Related labels:
source:juejin.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!