sweetalert

SweetAlert是一个美观的JavaScript插件,用于替换传统的alert对话框。它提供了丰富的功能和优雅的设计,包括错误消息、警告提示、输入框等交互。用户可以方便地安装、使用,并查看详细的文档和示例进行应用。此外,该项目欢迎社区贡献,有明确的贡献指南。
摘要由CSDN通过智能技术生成

sweetalert是什么

什么是sweetalert,SweetAlert 是一个 JavaScript 插件,能够完美替代 JavaScript 自带的 alert 弹出框,并且功能强大、设计优美。

sweetalert介绍

SweetAlert

A beautiful replacement for JavaScript’s “alert”

npm versionBuild status

A success modal

Installation

$ npm install --save sweetalert

Usage

import swal from 'sweetalert'

swal("Hello world!")

Upgrading from 1.X

Many improvements and breaking changes have been introduced in the 2.0 release. Make sure you read the upgrade guide to avoid nasty suprises!

Guides

Documentation

Examples

An error message:

swal("Oops!", "Something went wrong!", "error")

A warning message, with a function attached to the confirm message:

swal({
  title: "Are you sure?",
  text: "Are you sure that you want to leave this page?",
  icon: "warning",
  dangerMode: true,
})
.then(willDelete => {
  if (willDelete) {
    swal("Deleted!", "Your imaginary file has been deleted!", "success");
  }
});
const willDelete = await swal({
  title: "Are you sure?",
  text: "Are you sure that you want to delete this file?",
  icon: "warning",
  dangerMode: true,
})

if (willDelete) {
  swal("Deleted!", "Your imaginary file has been deleted!", "success");
}

A prompt modal, where the user’s input is logged:

swal("Type something:", {
  content: "input",
})
.then((value) => {
  swal(`You typed: ${value}`);
})
const value = await swal("Type something:", {
  content: "input",
})

swal(`You typed: ${value}`);

In combination with Fetch:

swal({
  text: 'Wanna log some information about Bulbasaur?',
  button: {
    text: "Search!",
    closeModal: false,
  },
})
.then(willSearch => {
  if (willSearch) {
    return fetch(`http://pokeapi.co/api/v2/pokemon/1`)
  }
})
.then(result => result.json())
.then(json => console.log(json))
.catch(err => {
  swal("Oops!", "Seems like we couldn't fetch the info", "error")
})
const willSearch = await swal({
  text: 'Wanna log some information about Bulbasaur?',
  button: {
    text: "Search!",
    closeModal: false,
  },
})

if (willSearch) {
  try {
    const result = await fetch(`http://pokeapi.co/api/v2/pokemon/1`)
    const json = await result.json()
    console.log(json)
  } catch (err) {
    swal("Oops!", "Seems like we couldn't fetch the info", "error")
  }
}

Contributing

If you’re changing the core library:

  1. Make changes in the src folder.
  2. Preview changes by running npm run docs
  3. Submit pull request

If you’re changing the documentation:

  1. Make changes in the docs-src folder.
  2. Preview changes by running npm run docs
  3. Run npm run builddocs to compile the changes to the docs folder
  4. Submit pull request

你可能感兴趣的文章:

本站文章除注明转载外,均为本站原创或编译。欢迎任何形式的转载,但请务必注明出处。

转载请注明:文章转载自 JavaScript中文网 [https://www.javascriptcn.com]

本文地址:https://www.javascriptcn.com/read-32285.html

文章标题:sweetalert

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值