search
HomeWeb Front-endVue.jsTreasure item! Share an out-of-the-box Vue3 component library: Varlet

This article will share with you an out-of-the-box Vue3 component library: Varlet. Let’s take a look at its functional features and briefly understand how to use it. I hope it will be helpful to everyone!

I believe many developers have had this idea: because they are interested in a certain technology stack or star open source project, they have the idea and practice of developing new projects in the expansion direction, and they also hope to This new open source project can also receive the same attention as other high-quality open source projects, but not every project can become popular and obtain high star numbers.

However, the developer of the open source project introduced today has achieved a gorgeous counterattack from scratch to one in the past year. Let’s do it together Look what a treasure project this is.

Varlet is a Material style mobile terminalcomponent library developed based on Vue3, and was recommended by Vue author You Yuxi at this year's Vue JS Live. However, it has been less than a year since the project was born. [Related recommendations: vuejs video tutorial]

I learned from a technical blog of the author of Varlet that the author is a Sichuan front-end developer who graduated from a junior college and works in Wuxi. Last year, because my unit planned to develop a component library related to Vue3, by chance, the author volunteered to take over the job. However, the company did not intend to provide support due to cost, return on investment and other reasons. Then the author and two friends decided to continue.

Treasure item! Share an out-of-the-box Vue3 component library: Varlet

This component library is standardized based on the design of Material Design. During this period, the author and the cooperating partners jointly referred to the community's finished products and combined with the interests of domestic developers api. As for why Material was chosen, the author described it in the official document:

In early mobile devices, large color blocks and strong contrasting colors placed high demands on display devices, while non-linear animation and water Ripple has certain requirements on the GPU. As a result, the Material style does not have a good experience in the mobile browser environment, and more flat and plain styles are chosen to invest in products. However, as the efficiency of runtime processing of modern devices and new js frameworks gradually improves, browsers have more free time and ability to process animation effects, and Material Design will bring a better experience to applications.

After many repeated deliberations, the component library has vaguely taken shape. From now on, Varlet is also officially open source and adopts the MIT open source license.

Treasure item! Share an out-of-the-box Vue3 component library: Varlet

In the days that followed, Varlet was not only recommended by teacher Ruan Yifeng, but also recognized by the foreign open source technology community, including the Antfu master of the Vite core team. PR for this component library. Not long ago, at Vue3’s 2021 annual summary sharing meeting, Master You Yuxi also recommended Varlet. Some time ago, the varlet-ui project, which was open source on Gitee, was evaluated and recommended by Gitee. The project address is: https://gitee.com/varlet/varlet-ui

So what exactly does Varlet have? What about the charm that attracts so many great people and high-quality platform promotions?


In terms of features

  • Provides 50 high-quality general components
  • The components are very lightweight
  • Developed and perfected by Chinese people Chinese and English documentation and logistical support
  • Support on-demand introduction
  • Support theme customization
  • Support internationalization
  • Support webstorm, vscode component attribute highlighting
  • Support SSR
  • Support Typescript
  • Ensure more than 90% unit test coverage and provide stability guarantee
  • Support dark mode

How to install and deploy

CDN

varlet.js contains all the styles and logic of the component library, so you only need to import it.

<div></div>
<script></script>
<script></script>
<script>
  const app = Vue.createApp({
    template: &#39;<var-button>按钮&#39;
  })
  app.use(Varlet).mount(&#39;#app&#39;)
</script>

Webpack/Vite

# 通过 npm、yarn 或 pnpm 安装

# npm
npm i @varlet/ui -S

# yarn
yarn add @varlet/ui

# pnpm
pnpm add @varlet/ui
import App from './App.vue'
import Varlet from '@varlet/ui'
import { createApp } from 'vue'
import '@varlet/ui/es/style.js'

createApp(App).use(Varlet).mount('#app')

How to introduce?

Treasure item! Share an out-of-the-box Vue3 component library: Varlet

Manual introduction

Each component is a Vue plug-in and consists of component logic and style files, as follows Manually introduced for use.

import { createApp } from 'vue'
import { Button } from '@varlet/ui'
import '@varlet/ui/es/button/style/index.js'

createApp().use(Button)

Automatic introduction

All components in the template will be automatically scanned by the unplugin-vue-components plug-in, and the plug-in will automatically introduce the components Logic and style files and register components.

# 安装插件

# npm
npm i unplugin-vue-components -D

# yarn
yarn add unplugin-vue-components -D

# pnpm
pnpm add unplugin-vue-components -D

Vue Cli

// vue.config.js
const Components = require('unplugin-vue-components/webpack')
const { VarletUIResolver } = require('unplugin-vue-components/resolvers')

module.exports = {
  configureWebpack: {
    plugins: [
      Components({
        resolvers: [VarletUIResolver()]
      })
    ]
  }
}

Vite

// vite.config.js
import vue from '@vitejs/plugin-vue'
import components from 'unplugin-vue-components/vite'
import { VarletUIResolver } from 'unplugin-vue-components/resolvers'
import { defineConfig } from 'vite'

export default defineConfig({
  plugins: [
    vue(),
    components({
      resolvers: [VarletUIResolver()]
    })
  ]
})

Note

After completing the configuration, you can use it as follows

<template>
  <var-button>默认按钮</var-button>
</template>

How to switch themes

This project provides a dark mode theme. The advantage of dark mode is that it has higher readability in low-light environments.

Treasure item! Share an out-of-the-box Vue3 component library: Varlet

<var-button>切换主题</var-button>复制代码
import dark from '@varlet/ui/es/themes/dark'
import { StyleProvider } from '@varlet/ui'

export default {
  setup() {
    let currentTheme
    
    const toggleTheme = () => {
      currentTheme = currentTheme ? null : dark
      StyleProvider(currentTheme)
    }
    
    return { toggleTheme }
  }
}

Inject the text color and background color variables recommended by the component library to control the overall color

body {
  transition: background-color .25s;
  color: var(--color-text);
  background-color: var(--color-body);
}

样式展示

Treasure item! Share an out-of-the-box Vue3 component library: Varlet

Treasure item! Share an out-of-the-box Vue3 component library: Varlet

在线编辑地址

前往下列网址:https://varlet.gitee.io/varlet-ui/#/zh-CN/quickstart

点击界面右上方:

  Treasure item! Share an out-of-the-box Vue3 component library: Varlet

(学习视频分享:vuejs教程web前端

The above is the detailed content of Treasure item! Share an out-of-the-box Vue3 component library: Varlet. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:掘金社区. If there is any infringement, please contact admin@php.cn delete
What Happens When the Vue.js Virtual DOM Detects a Change?What Happens When the Vue.js Virtual DOM Detects a Change?May 14, 2025 am 12:12 AM

WhentheVue.jsVirtualDOMdetectsachange,itupdatestheVirtualDOM,diffsit,andappliesminimalchangestotherealDOM.ThisprocessensureshighperformancebyavoidingunnecessaryDOMmanipulations.

How Accurate Is It to Think of Vue.js's Virtual DOM as a Mirror of the Real DOM?How Accurate Is It to Think of Vue.js's Virtual DOM as a Mirror of the Real DOM?May 13, 2025 pm 04:05 PM

Vue.js' VirtualDOM is both a mirror of the real DOM, and not exactly. 1. Create and update: Vue.js creates a VirtualDOM tree based on component definitions, and updates VirtualDOM first when the state changes. 2. Differences and patching: Comparison of old and new VirtualDOMs through diff operations, and apply only the minimum changes to the real DOM. 3. Efficiency: VirtualDOM allows batch updates, reduces direct DOM operations, and optimizes the rendering process. VirtualDOM is a strategic tool for Vue.js to optimize UI updates.

Vue.js vs. React: Scalability and MaintainabilityVue.js vs. React: Scalability and MaintainabilityMay 10, 2025 am 12:24 AM

Vue.js and React each have their own advantages in scalability and maintainability. 1) Vue.js is easy to use and is suitable for small projects. The Composition API improves the maintainability of large projects. 2) React is suitable for large and complex projects, with Hooks and virtual DOM improving performance and maintainability, but the learning curve is steeper.

The Future of Vue.js and React: Trends and PredictionsThe Future of Vue.js and React: Trends and PredictionsMay 09, 2025 am 12:12 AM

The future trends and forecasts of Vue.js and React are: 1) Vue.js will be widely used in enterprise-level applications and have made breakthroughs in server-side rendering and static site generation; 2) React will innovate in server components and data acquisition, and further optimize the concurrency model.

Netflix's Frontend: A Deep Dive into Its Technology StackNetflix's Frontend: A Deep Dive into Its Technology StackMay 08, 2025 am 12:11 AM

Netflix's front-end technology stack is mainly based on React and Redux. 1.React is used to build high-performance single-page applications, and improves code reusability and maintenance through component development. 2. Redux is used for state management to ensure that state changes are predictable and traceable. 3. The toolchain includes Webpack, Babel, Jest and Enzyme to ensure code quality and performance. 4. Performance optimization is achieved through code segmentation, lazy loading and server-side rendering to improve user experience.

Vue.js and the Frontend: Building Interactive User InterfacesVue.js and the Frontend: Building Interactive User InterfacesMay 06, 2025 am 12:02 AM

Vue.js is a progressive framework suitable for building highly interactive user interfaces. Its core functions include responsive systems, component development and routing management. 1) The responsive system realizes data monitoring through Object.defineProperty or Proxy, and automatically updates the interface. 2) Component development allows the interface to be split into reusable modules. 3) VueRouter supports single-page applications to improve user experience.

What are the disadvantages of VueJs?What are the disadvantages of VueJs?May 05, 2025 am 12:06 AM

The main disadvantages of Vue.js include: 1. The ecosystem is relatively new, and third-party libraries and tools are not as rich as other frameworks; 2. The learning curve becomes steep in complex functions; 3. Community support and resources are not as extensive as React and Angular; 4. Performance problems may be encountered in large applications; 5. Version upgrades and compatibility challenges are greater.

Netflix: Unveiling Its Frontend FrameworksNetflix: Unveiling Its Frontend FrameworksMay 04, 2025 am 12:16 AM

Netflix uses React as its front-end framework. 1.React's component development and virtual DOM mechanism improve performance and development efficiency. 2. Use Webpack and Babel to optimize code construction and deployment. 3. Use code segmentation, server-side rendering and caching strategies for performance optimization.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor