【问题标题】:How to return HTML within an Object using React and SweetAlert2如何使用 React 和 SweetAlert2 在对象中返回 HTML
【发布时间】:2025-11-28 04:00:02
【问题描述】:

我想在文本字段中使用SweetAlert2 显示图像。我相信 SweetAlert 只是返回和反对。这是它的样子:

swal({
  title: 'Title',
  text: 'text',
  type: 'success'
})

其中的每一个通常都带有一个字符串。我想要做的是在文本字段中显示和图像。我尝试做 text: (<img src="image_src" />) ,但这不起作用,它只是在警报中显示 [ojbect Object]

我应该注意到这一点,但我也在 src 中为图像添加了一个变量。所以我需要这个以某种方式工作

<img src={`${image_url}`} />

如果您需要更多代码,请告诉我!

【问题讨论】:

标签: javascript reactjs sweetalert sweetalert2


【解决方案1】:

感谢@helb 提供的有用的 cmets,我发现而不是使用

swal({
  title: 'Title',
  text: 'text',
  type: 'success'
})

我需要这样做:

swal({
  title: 'Title',
  html: `<img src='${image_url}'/>`,
  type: 'success'
})

【讨论】:

    最近更新 更多