注: 由于此组件基于 create-api 实现,所以在使用之前,请确保自己了解过 。

    • 类型设置
      1. export default {
      2. methods: {
      3. showAlert() {
      4. this.- createDialog({
      5. type: 'alert',
      6. title: '我是标题',
      7. content: '我是内容',
      8. icon: 'cubeic-alert'
      9. }).show()
      10. }
      11. }
      12. }
    • 按钮设置
      1. export default {
      2. methods: {
      3. showBtn() {
      4. this.- createDialog({
      5. type: 'confirm',
      6. icon: 'cubeic-alert',
      7. title: '我是标题',
      8. content: '我是内容',
      9. confirmBtn: {
      10. text: '确定按钮',
      11. active: true,
      12. disabled: false,
      13. href: 'javascript:;'
      14. },
      15. cancelBtn: {
      16. text: '取消按钮',
      17. active: false,
      18. disabled: false,
      19. href: 'javascript:;'
      20. onConfirm: () => {
      21. this.- createToast({
      22. type: 'warn',
      23. time: 1000,
      24. txt: '点击确认按钮'
      25. }).show()
      26. },
      27. onCancel: () => {
      28. this.- createToast({
      29. type: 'warn',
      30. time: 1000,
      31. txt: '点击取消按钮'
      32. }).show()
      33. }
      34. }).show()
      35. }
      36. }
      37. }

    按钮设置可接受 String 或 Object 类型数据,当传入 Object 类型的数据时,可通过 text 字段来设置按钮文案内容、active 字段来设置按钮文案是否高亮、disabled 字段来设置按钮是否禁用、href 字段为按钮的跳转链接。

    • 关闭按钮
      1. export default {
      2. methods: {
      3. showClose() {
      4. this.- createDialog({
      5. type: 'alert',
      6. icon: 'cubeic-alert',
      7. showClose: true,
      8. title: '标题',
      9. onClose: () => {
      10. this.- createToast({
      11. type: 'warn',
      12. time: 1000,
      13. txt: '点击关闭按钮'
      14. }).show()
      15. }
      16. }).show()
      17. }
      18. }
      19. }
    • createDialog 的第二个参数是 render 函数,一般用于处理插槽的场景;Dialog 组件提供了 2 个具名的插槽 title 和 content,分别用来分发标题和内容。
    • confirmBtn 子配置项
    参数 说明 类型 可选值 默认值
    text 按钮文案 String - '确认'
    active 是否高亮 Boolean true/false true
    disabled 是否禁用 Boolean true/false false
    href 点击按钮后的跳转链接 String - 'javascript:;'
    • cancelBtn 子配置项
    名字 说明 作用域参数
    title 标题 -
    content 内容 -
    方法名 说明
    show 显示
    hide 隐藏

    原文: