一个轻量级、无依赖的 Loading 插件 —— @lijixuan/loading

  • 🚀 一个轻量级、无依赖的 Loading 插件 ------ @lijixuan/loading
  • 📦 NPM地址:https://www.npmjs.com/package/@lijixuan/loading
  • 🧩 GitHub地址:https://github.com/lidaxuan/ldx-loading

前言 开发中,我们经常需要一个简洁好用的 Loading 组件,无论是请求数据时的全局遮罩,还是局部区域的加载提示,性能、兼容性和易用性都非常关键。在vue2中使用太过于繁琐!!!

html 复制代码
<template>
  <div class="" v-loading="loading"></div>
</template>
<script>
export default {
  data() {
    return {
      loading: false
    };
  },
  mounted() {
    this.loading = true;
    setTimeout(() => {
      this.loading = false;
    }, 2000);
  },
};
</script>

于是我开发了一个零依赖、支持原生 HTML、Vue2、Vue3 的 Loading 插件:@lijixuan/loading。欢迎大家试用、提 issue 或 PR!

✨ 项目特色

  • ✅ 零依赖:无需引入任何第三方库,纯原生 JS 实现。
  • 🎯 多框架支持:可直接用于 Vue2、Vue3 项目,也可在 原生 HTML 项目中直接调用。
  • 🎨 样式灵活:支持自定义颜色、文本、类名,支持全屏/局部模式。
  • 🧠 防重复点击机制:自动禁用触发按钮,防止重复提交请求。
  • 🧩 Element UI 风格:内置样式参考 Element UI,默认美观,开箱即用。
  • 🪄 按需调用:提供 open() / close() 方法,使用方式清晰明了。

🚀 快速开始 安装 npm i @lijixuan/loading或者yarn add @lijixuan/loading

使用方式 Vue2 / Vue3 中使用

javascript 复制代码
<template>
  <div class="page-asd">
    <div>
      <div v-for="item in 3" :key="item">奥术大师多反而AV方式变奥术大师多反而AV方式变奥术大师多反而AV方式变奥术大师多反而AV方式变奥术大师多反而AV方式变</div>
    </div>
    <el-button  @click="click1($event)">按钮1</el-button>
    <el-button type="primary" @click="click2($event)">按钮2</el-button>
    <div type="primary" @click="click2($event)">按钮3-div</div>
  </div>
</template>

<script>
import LdxLoading from "./LdxLoading.js";

LdxLoading.init({
  text: "加载中...",
  customClass: "ldx-loading",
  color: 'green',
  // fullscreen:false
})
export default {
  components: {
    Comp,Compcopy
  },
  props: {},
  data() {
    return {
      query: {
        name: "zs"
      },
    };
  },
  mounted() {
    // this.initPage();
  },
  methods: {
    async initPage() {
      const el = document.querySelector('.page-asd')
      LdxLoading.open(el, {text: "页面加载中"});
      const res = await this.getData(this.query);
      LdxLoading.close(el);
    },
    getData(query) {
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve({...query, age: 18});
        }, 1000);
      });
    },
    click1(event) {
      console.log("点击了")
      this.initPage();
    },
    click2(event) {
      console.log("event", Array.from(event.target.classList).includes('ldx-loading-mask'));
      const el = event.currentTarget; // 或 event.target
      LdxLoading.open(el, {text: ""});
      setTimeout(() => {
        LdxLoading.close(el);
      }, 3000);
    }
  }
};
</script>
<style lang="scss" scoped>
.page-asd {
  width: 100%;
  height: 100%;
  background: pink;
  overflow-y: auto;
}
</style>

⚙️ 参数说明

参数 类型 默认值 说明
target HTMLElement Event document.body 触发的元素
text string "" loading 文案
fullscreen boolean false 是否全屏遮罩
lock boolean true 是否禁用目标按钮
customClass string '' 自定义类名
color string #409EFF loading 颜色

📦 源码仓库 欢迎 star、fork、提 issue! 👉 GitHub地址:https://github.com/lidaxuan/ldx-loading

🤝 结语 这是一个简洁但实用的插件,希望能帮到你简化开发流程。未来我还会持续优化,计划加入:

✅ 自定义 SVG 动画支持

✅ 多实例栈管理

✅ 持续交互提示(如圈圈转 + 进度条)

如果你觉得这个项目有用,欢迎点个 Star ⭐,也欢迎在实际项目中应用它!你的鼓励是我持续更新的最大动力!

相关推荐
curdcv_po6 分钟前
🔥🔥🔥结合 vue 或 react,去写three.js
前端·react.js·three.js
猫头_34 分钟前
uni-app 转微信小程序 · 避坑与实战全记录
前端·微信小程序·uni-app
天生我材必有用_吴用37 分钟前
网页接入弹窗客服功能的完整实现(Vue3 + WebSocket预备方案)
前端
海拥42 分钟前
8 Ball Pool:在浏览器里打一局酣畅淋漓的桌球!
前端
Cache技术分享1 小时前
148. Java Lambda 表达式 - 捕获局部变量
前端·后端
明长歌1 小时前
【javascript】Reflect学习笔记
javascript·笔记·学习
YGY Webgis糕手之路1 小时前
Cesium 快速入门(二)底图更换
前端·经验分享·笔记·vue
神仙别闹1 小时前
基于JSP+MySQL 实现(Web)毕业设计题目收集系统
java·前端·mysql
前端李二牛1 小时前
Web字体使用最佳实践
前端·http
YGY_Webgis糕手之路1 小时前
Cesium 快速入门(六)实体类型介绍
前端·gis·cesium