Alert警告提示 - 图1

Alert 警告提示

警告提示,展现需要关注的信息。

何时使用

  • 当某个页面需要向用户显示警告的信息时。
  • 非浮层的静态展现形式,始终展现,不会自动消失,用户可以点击关闭。

代码演示

Alert警告提示 - 图2

基本用法

最简单的用法,适用于简短的警告提示。

  1. <template>
  2. <a-alert message="Success Text" type="success" />
  3. </template>

Alert警告提示 - 图3

Alert警告提示 - 图4

可关闭的警告提示

显示关闭按钮,点击可关闭警告提示。

  1. <template>
  2. <a-alert
  3. message="Warning Text Warning Text Warning TextW arning Text Warning Text Warning TextWarning Text"
  4. type="warning"
  5. closable
  6. @close="onClose"
  7. />
  8. <a-alert
  9. message="Error Text"
  10. description="Error Description Error Description Error Description Error Description Error Description Error Description"
  11. type="error"
  12. closable
  13. @close="onClose"
  14. />
  15. </template>
  16. <script lang="ts">
  17. import { defineComponent } from 'vue';
  18. export default defineComponent({
  19. setup() {
  20. const onClose = (e: MouseEvent) => {
  21. console.log(e, 'I was closed.');
  22. };
  23. return {
  24. onClose,
  25. };
  26. },
  27. });
  28. </script>

Alert警告提示 - 图5

Alert警告提示 - 图6

Alert警告提示 - 图7

Alert警告提示 - 图8

Alert警告提示 - 图9

Alert警告提示 - 图10

Alert警告提示 - 图11

Alert警告提示 - 图12

图标

可口的图标让信息类型更加醒目。

  1. <template>
  2. <a-alert message="Success Tips" type="success" show-icon />
  3. <a-alert message="Informational Notes" type="info" show-icon />
  4. <a-alert message="Warning" type="warning" show-icon />
  5. <a-alert message="Error" type="error" show-icon />
  6. <a-alert
  7. message="Success Tips"
  8. description="Detailed description and advices about successful copywriting."
  9. type="success"
  10. show-icon
  11. />
  12. <a-alert
  13. message="Informational Notes"
  14. description="Additional description and informations about copywriting."
  15. type="info"
  16. show-icon
  17. />
  18. <a-alert
  19. message="Warning"
  20. description="This is a warning notice about copywriting."
  21. type="warning"
  22. show-icon
  23. />
  24. <a-alert
  25. message="Error"
  26. description="This is an error message about copywriting."
  27. type="error"
  28. show-icon
  29. />
  30. </template>

Alert警告提示 - 图13

Alert警告提示 - 图14

Alert警告提示 - 图15

Alert警告提示 - 图16

顶部公告

最简单的用法,适用于简短的警告提示。

  1. <template>
  2. <a-alert message="Warning text" banner />
  3. <br />
  4. <a-alert
  5. message="Very long warning text warning text text text text text text text"
  6. banner
  7. closable
  8. />
  9. <br />
  10. <a-alert :show-icon="false" message="Warning text without icon" banner />
  11. <br />
  12. <a-alert type="error" message="Error text" banner />
  13. </template>

Alert警告提示 - 图17

平滑地卸载

平滑、自然的卸载提示。

  1. <template>
  2. <a-alert
  3. v-if="visible"
  4. message="Alert Message Text"
  5. type="success"
  6. closable
  7. :after-close="handleClose"
  8. />
  9. </template>
  10. <script lang="ts">
  11. import { defineComponent, ref } from 'vue';
  12. export default defineComponent({
  13. setup() {
  14. const visible = ref<boolean>(true);
  15. const handleClose = () => {
  16. visible.value = false;
  17. };
  18. return {
  19. visible,
  20. handleClose,
  21. };
  22. },
  23. });
  24. </script>

Alert警告提示 - 图18

Alert警告提示 - 图19

Alert警告提示 - 图20

Alert警告提示 - 图21

四种样式

共有四种样式 successinfowarningerror

  1. <template>
  2. <a-alert message="Success Text" type="success" />
  3. <a-alert message="Info Text" type="info" />
  4. <a-alert message="Warning Text" type="warning" />
  5. <a-alert message="Error Text" type="error" />
  6. </template>

Alert警告提示 - 图22

Alert警告提示 - 图23

Alert警告提示 - 图24

Alert警告提示 - 图25

含有辅助性文字介绍

含有辅助性文字介绍的警告提示。

  1. <template>
  2. <a-alert message="Success Text" type="success">
  3. <template #description>
  4. <p>
  5. Success Description
  6. <span style="color: red">Success</span>
  7. Description Success Description
  8. </p>
  9. </template>
  10. </a-alert>
  11. <a-alert
  12. message="Info Text"
  13. description="Info Description Info Description Info Description Info Description"
  14. type="info"
  15. />
  16. <a-alert
  17. message="Warning Text"
  18. description="Warning Description Warning Description Warning Description Warning Description"
  19. type="warning"
  20. />
  21. <a-alert
  22. message="Error Text"
  23. description="Error Description Error Description Error Description Error Description"
  24. type="error"
  25. />
  26. </template>

Alert警告提示 - 图26

自定义关闭

自定义图标让信息类型更加醒目。

  1. <template>
  2. <a-alert message="Info Text" type="info" close-text="Close Now" />
  3. </template>

Alert警告提示 - 图27

Alert警告提示 - 图28

Alert警告提示 - 图29

Alert警告提示 - 图30

Alert警告提示 - 图31

Alert警告提示 - 图32

Alert警告提示 - 图33

Alert警告提示 - 图34

Alert警告提示 - 图35

自定义图标

可以自定义关闭,自定义的文字会替换原先的关闭 Icon

  1. <template>
  2. <a-alert message="showIcon = false" type="success">
  3. <template #icon><smile-outlined /></template>
  4. </a-alert>
  5. <a-alert message="Success Tips" type="success" showIcon>
  6. <template #icon><smile-outlined /></template>
  7. </a-alert>
  8. <a-alert message="Informational Notes" type="info" showIcon>
  9. <template #icon><smile-outlined /></template>
  10. </a-alert>
  11. <a-alert message="Warning" type="warning" showIcon>
  12. <template #icon><smile-outlined /></template>
  13. </a-alert>
  14. <a-alert message="Error" type="error" showIcon>
  15. <template #icon><smile-outlined /></template>
  16. </a-alert>
  17. <a-alert
  18. message="Success Tips"
  19. description="Detailed description and advices about successful copywriting."
  20. type="success"
  21. show-icon
  22. >
  23. <template #icon><smile-outlined /></template>
  24. </a-alert>
  25. <a-alert
  26. message="Informational Notes"
  27. description="Additional description and informations about copywriting."
  28. type="info"
  29. show-icon
  30. >
  31. <template #icon><smile-outlined /></template>
  32. </a-alert>
  33. <a-alert
  34. message="Warning"
  35. description="This is a warning notice about copywriting."
  36. type="warning"
  37. show-icon
  38. >
  39. <template #icon><smile-outlined /></template>
  40. </a-alert>
  41. <a-alert
  42. message="Error"
  43. description="This is an error message about copywriting."
  44. type="error"
  45. show-icon
  46. >
  47. <template #icon><smile-outlined /></template>
  48. </a-alert>
  49. </template>
  50. <script lang="ts">
  51. import { SmileOutlined } from '@ant-design/icons-vue';
  52. import { defineComponent } from 'vue';
  53. export default defineComponent({
  54. components: {
  55. SmileOutlined,
  56. },
  57. });
  58. </script>

API

参数说明类型默认值版本
afterClose关闭动画结束后触发的回调函数() => void-
banner是否用作顶部公告booleanfalse
closable默认不显示关闭按钮boolean
closeText自定义关闭按钮string|slot
description警告提示的辅助性文字介绍string|slot
icon自定义图标,showIcontrue 时有效vnode|slot-
message警告提示内容string|slot
showIcon是否显示辅助图标booleanfalse,banner 模式下默认值为 true
type指定警告提示的样式,有四种选择 successinfowarningerrorstringinfo,banner 模式下默认值为 warning

事件

事件名称说明回调参数版本
close关闭时触发的回调函数(e: MouseEvent) => void-