SweetAlert2: 未知参数 “onOpen” 如何解决此警告?

huangapple go评论60阅读模式
英文:

how can I resolve this warning: SweetAlert2: Unknown parameter "onOpen"?

问题

以下是代码部分的翻译:

my sweet alert show this warning, how can I resolve this? any idea
我的Sweet Alert显示这个警告如何解决有什么想法
don't know what causes this warning when I fire this Sweet Alert, it shows this warning.
不知道在我触发Sweet Alert时是什么导致了这个警告它显示这个警告
here is the alert component code:
这是警报组件的代码
import Swal from "sweetalert2";
import Swal from "sweetalert2";
const ToastComponent = Swal.mixin({
const ToastComponent = Swal.mixin({
  toast: true,
  position: "top-end",
  showConfirmButton: false,
  timer: 3000,
  timerProgressBar: true,
  onOpen: (toast) => {
    toast.addEventListener("mouseenter", Swal.stopTimer);
    toast.addEventListener("mouseleave", Swal.resumeTimer);
  },
});
  toast: true,
  position: "top-end",
  showConfirmButton: false,
  timer: 3000,
  timerProgressBar: true,
  onOpen: (toast) => {
    toast.addEventListener("mouseenter", Swal.stopTimer);
    toast.addEventListener("mouseleave", Swal.resumeTimer);
  },
});
export const Alert = (type = "", title = "", description = "") =>
  Swal.fire(title, description, type);
export const Alert = (type = "", title = "", description = "") =>
  Swal.fire(title, description, type);
export const Toast = (type = "", title = "") =>
  ToastComponent.fire({
    icon: type,
    title,
  });
export const Toast = (type = "", title = "") =>
  ToastComponent.fire({
    icon: type,
    title,
  });

请注意,上述翻译中,我将HTML实体编码"转换为双引号"以更好地呈现代码。如果您需要进一步的帮助,请随时提问。

英文:

my sweet alert show this warning, how can I resolve this? any idea
SweetAlert2: 未知参数 “onOpen” 如何解决此警告?
SweetAlert2: 未知参数 “onOpen” 如何解决此警告?

don't know what causes this warning when I fire this Sweet Alert, it shows this warning.

here is the alert component code:

    import Swal from "sweetalert2";

const ToastComponent = Swal.mixin({
  toast: true,
  position: "top-end",
  showConfirmButton: false,
  timer: 3000,
  timerProgressBar: true,
  onOpen: (toast) => {
    toast.addEventListener("mouseenter", Swal.stopTimer);
    toast.addEventListener("mouseleave", Swal.resumeTimer);
  },
});

export const Alert = (type = "", title = "", description = "") =>
  Swal.fire(title, description, type);

export const Toast = (type = "", title = "") =>
  ToastComponent.fire({
    icon: type,
    title,
  });

答案1

得分: 1

From

onOpen: (toast) => {
  toast.addEventListener("mouseenter", Swal.stopTimer);
  toast.addEventListener("mouseleave", Swal.resumeTimer);
}

To

didOpen: (toast) => {
  toast.addEventListener('mouseenter', Swal.stopTimer);
  toast.addEventListener('mouseleave', Swal.resumeTimer);
}
英文:

In case of onOpen didn't work, I think you can use didOpen.

From

onOpen: (toast) => {
  toast.addEventListener("mouseenter", Swal.stopTimer);
  toast.addEventListener("mouseleave", Swal.resumeTimer);
}

To

didOpen: (toast) => {
  toast.addEventListener('mouseenter', Swal.stopTimer)
  toast.addEventListener('mouseleave', Swal.resumeTimer)
}

I made a playground here.
Codepen.

huangapple
  • 本文由 发表于 2023年4月4日 13:59:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/75925943.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定