Poptip 气泡提示

    Poptip 与 Tooltip 类似,具有很多相同配置,不同点是 Poptip 以卡片的形式承载了更多的内容,比如链接、表格、按钮等。

    Poptip 还 confirm 确认框,与 Modal 不同的是,它会出现在就近元素,相对轻量。

    基础用法

    支持三种触发方式:鼠标悬停、点击、聚焦。默认是点击。

    注意 Poptip 内的文本使用了 ,即不自动换行,如需展示很多内容并自动换行时,建议给内容 slot 增加样式 white-space: normal;

    Poptip 气泡提示 - 图2

    组件提供了12个不同的方向显示Poptip,具体配置可查看API。。

    1. <style scoped>
    2. .top,.bottom{
    3. text-align: center;
    4. }
    5. .center{
    6. width: 300px;
    7. margin: 10px auto;
    8. overflow: hidden;
    9. }
    10. .center-left{
    11. float: left;
    12. }
    13. .center-right{
    14. float: right;
    15. }
    16. </style>
    17. <template>
    18. <div class="top">
    19. <Poptip title="Title" content="content" placement="top-start">
    20. <Button>Top Left</Button>
    21. </Poptip>
    22. <Poptip title="Title" content="content" placement="top">
    23. <Button>Top Center</Button>
    24. </Poptip>
    25. <Poptip title="Title" content="content" placement="top-end">
    26. <Button>Top Right</Button>
    27. </Poptip>
    28. </div>
    29. <div class="center">
    30. <div class="center-left">
    31. <Poptip title="Title" content="content" placement="left-start">
    32. <Button>Left Top</Button>
    33. </Poptip><br><br>
    34. <Poptip title="Title" content="content" placement="left">
    35. <Button>Left Center</Button>
    36. </Poptip><br><br>
    37. <Poptip title="Title" content="content" placement="left-end">
    38. <Button>Left Bottom</Button>
    39. </Poptip>
    40. </div>
    41. <div class="center-right">
    42. <Button>Right Top</Button>
    43. </Poptip><br><br>
    44. <Poptip title="Title" content="content" placement="right">
    45. <Button>Right Center</Button>
    46. </Poptip><br><br>
    47. <Poptip title="Title" content="content" placement="right-end">
    48. <Button>Right Bottom</Button>
    49. </Poptip>
    50. </div>
    51. <div class="bottom">
    52. <Poptip title="Title" content="content" placement="bottom-start">
    53. <Button>Bottom Left</Button>
    54. </Poptip>
    55. <Poptip title="Title" content="content" placement="bottom">
    56. <Button>Bottom Center</Button>
    57. </Poptip>
    58. <Poptip title="Title" content="content" placement="bottom-end">
    59. <Button>Bottom Right</Button>
    60. </Poptip>
    61. </div>
    62. </template>
    63. <script>
    64. export default {
    65. }
    66. </script>

    从浮层内关闭

    通过v-model来控制提示框的显示和隐藏。

    Poptip 气泡提示 - 图4

    嵌套复杂内容

    通过自定义 slot 来实现复杂的内容。

    1. <template>
    2. <Poptip placement="right" width="400">
    3. <Button>Click</Button>
    4. <div class="api" slot="content">
    5. <table>
    6. <thead>
    7. <tr>
    8. <th>Version</th>
    9. <th>Update Time</th>
    10. <th>Description</th>
    11. </tr>
    12. </thead>
    13. <tbody>
    14. <tr>
    15. <td>0.9.5</td>
    16. <td>2016-10-26</td>
    17. <td>Add new components <code>Tooltip</code> and <code>Poptip</code></td>
    18. </tr>
    19. <tr>
    20. <td>0.9.4</td>
    21. <td>Add new components <code>Modal</code></td>
    22. </tr>
    23. <tr>
    24. <td>0.9.2</td>
    25. <td>2016-09-28</td>
    26. <td>Add new components <code>Select</code></td>
    27. </tr>
    28. </tbody>
    29. </table>
    30. </div>
    31. </Poptip>
    32. </template>
    33. <script>
    34. }
    35. </script>

    设置属性 word-wrap,当超出宽度后,文本将自动换行,并两端对齐。

    Poptip 气泡提示 - 图6

    确认框

    通过设置属性confirm开启确认框模式。确认框只会以 click 的形式激活,并且只会显示 title 的内容,忽略 content。

    1. <template>
    2. <Poptip
    3. confirm
    4. title="Are you sure you want to delete this item?"
    5. @on-ok="ok"
    6. @on-cancel="cancel">
    7. <Button>Delete</Button>
    8. </Poptip>
    9. <Poptip
    10. confirm
    11. title="Are you sure delete this task?"
    12. @on-ok="ok"
    13. @on-cancel="cancel"
    14. ok-text="yes"
    15. cancel-text="no">
    16. <Button>Internationalization</Button>
    17. </Poptip>
    18. </template>
    19. <script>
    20. export default {
    21. methods: {
    22. ok () {
    23. this.$Message.info('You click ok');
    24. },
    25. cancel () {
    26. this.$Message.info('You click cancel');
    27. }
    28. }
    29. }
    30. </script>