uni-tooltip.vue 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <template>
  2. <view class="uni-tooltip">
  3. <slot></slot>
  4. <view v-if="content || $slots.content" class="uni-tooltip-popup">
  5. <slot name="content">
  6. {{content}}
  7. </slot>
  8. </view>
  9. </view>
  10. </template>
  11. <script>
  12. /**
  13. * Tooltip 提示文字
  14. * @description 常用于展示鼠标 hover 时的提示信息。
  15. * @tutorial https://uniapp.dcloud.io/component/uniui/uni-tooltip
  16. * @property {String} content 弹出层显示的内容
  17. * @property {String} placement出现位置, 目前只支持 left
  18. */
  19. export default {
  20. name: "uni-tooltip",
  21. data() {
  22. return {
  23. };
  24. },
  25. props: {
  26. content: {
  27. type: String,
  28. default: ''
  29. },
  30. placement: {
  31. type: String,
  32. default: 'bottom'
  33. },
  34. }
  35. }
  36. </script>
  37. <style>
  38. .uni-tooltip {
  39. position: relative;
  40. cursor: pointer;
  41. }
  42. .uni-tooltip-popup {
  43. z-index: 1;
  44. display: none;
  45. position: absolute;
  46. left: 0;
  47. background-color: #333;
  48. border-radius: 8px;
  49. color: #fff;
  50. font-size: 12px;
  51. text-align: left;
  52. line-height: 16px;
  53. padding: 12px;
  54. }
  55. .uni-tooltip:hover .uni-tooltip-popup {
  56. display: block;
  57. }
  58. </style>