一个轻量级、无依赖的 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 ⭐,也欢迎在实际项目中应用它!你的鼓励是我持续更新的最大动力!

相关推荐
passerby606130 分钟前
完成前端时间处理的另一块版图
前端·github·web components
掘了38 分钟前
「2025 年终总结」在所有失去的人中,我最怀念我自己
前端·后端·年终总结
崔庆才丨静觅41 分钟前
实用免费的 Short URL 短链接 API 对接说明
前端
崔庆才丨静觅1 小时前
5分钟快速搭建 AI 平台并用它赚钱!
前端
崔庆才丨静觅1 小时前
比官方便宜一半以上!Midjourney API 申请及使用
前端
Moment2 小时前
富文本编辑器在 AI 时代为什么这么受欢迎
前端·javascript·后端
崔庆才丨静觅2 小时前
刷屏全网的“nano-banana”API接入指南!0.1元/张量产高清创意图,开发者必藏
前端
剪刀石头布啊2 小时前
jwt介绍
前端
爱敲代码的小鱼2 小时前
AJAX(异步交互的技术来实现从服务端中获取数据):
前端·javascript·ajax
吹牛不交税2 小时前
admin.net-v2 框架使用笔记-netcore8.0/10.0版
vue.js·.netcore