npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@sunwise/use-el-dialog

v1.0.2

Published

通过hook方式调用element-plus的el-dialog

Downloads

3

Readme

use-el-dialog

在过去使用 el-dialog 过程中,我常常需要声明一系列的变量,来进行弹框加载状态的控制,弹框的展示与隐藏。

use-el-dialog 集成了常用的与弹框相关的功能,它包括了确认按钮的状态加载,嵌套组件的重新挂载等功能。实现了通过 hook 方式,直接调用 el-dialog 。

支持环境:vue3 + element-plus

你可能以往这样使用

<template>
  <el-button text @click="dialogVisible = true"> open the Dialog </el-button>

  <el-dialog v-model="dialogVisible" title="Tips" width="30%">
    <span>This is a message</span>
  </el-dialog>
</template>

<script lang="ts" setup>
import { ref } from "vue";

const dialogVisible = ref(false);
</script>

如果实现表单的弹框嵌套,实际逻辑更复杂,涉及到了表单的数据获取,弹框按钮的 loading 状态,弹框的展示与隐藏等控制,实现这些功能,需要通过声明大量的额外变量进行控制。

查看 demo

cd demo
yarn run dev

通过 use-el-dialog 的使用方式

main.js 中

import ElementPlus from "element-plus";
import "element-plus/dist/index.css";

import BasicElDialog from "@sunwise/use-el-dialog";
import "@sunwise/use-el-dialog/dist/style.css";

createApp(App)
  .use(BasicElDialog, {
    subBtuText: "确认",
    cancelBtuText: "取消",
  })
  .use(ElementPlus)
  .mount("#app");

vue file

<template>
  <div class="box-container">
    <el-button size="large" @click="handleOpen">Open Dialog</el-button>

    <basic-el-dialog @register="registerDialog" />
  </div>
</template>

<script lang="ts" setup>
import { useElDialog } from "use-el-dialog";

const [registerDialog, dialogMethods] = useElDialog({
  title: "Custom",
});

const handleOpen = () => {
  dialogMethods.openModal();
};
</script>

Attributes

use-el-dialog 继承了 el-dialog 的属性,在此基础之上还实现了其他属性

| 参数 | 说明 | 类型 | 可选值 | 默认值 | 是否必填 | | -------------- | -------------------------------- | ------- | ------ | ------ | -------- | | subBtuText | 弹框确认按钮文案 | string | 确认 | 否 | | cancelBtuText | 弹框取消按钮文案 | string | 取消 | 否 | | reload | 是否每次弹框展示时触发子组件重载 | boolean | false | 否 | | fullscreenIcon | 是否显示全屏按钮 | boolean | false | 否 |

Methods

| 名称 | 说明 | 参数 | | -------------- | -------------------------- | ------------------ | | openModal | 打开弹框 | - | | closeModal | 关闭弹框 | - | | setSubLoading | 设置“确认”按钮加载状态 | (state: boolean) | | setSubDisabled | 设置“确认”按钮不可点击状态 | (state: boolean) | | setProps | 动态设置属性 | use-el-dialog attr |

Events

| 名称 | 说明 | 参数 | | --------- | -------------- | -------- | | on-open | 弹窗打开后回调 | Function | | on-ok | 按钮“确认”回调 | Function | | on-cancel | 按钮“取消”回调 | Function |

Slots

| 名称 | 说明 | 参数 | | ------- | -------- | ---- | | header | 头部插槽 | - | | default | 中间插槽 | - | | footer | 脚部插槽 | - |

use-el-dialog 使用的前提,需要保证 element-plus 正确引入并使用。use-el-dialog 本身并不携带 element-plus。