1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
| <template>
| <view class="uni-tooltip">
| <slot></slot>
| <view v-if="content || $slots.content" class="uni-tooltip-popup" :style="initPlacement">
| <slot name="content">
| {{content}}
| </slot>
| </view>
| </view>
| </template>
|
|
| <script>
| /**
| * Tooltip 提示文字
| * @description 常用于展示鼠标 hover 时的提示信息。
| * @tutorial https://uniapp.dcloud.io/component/uniui/uni-tooltip
| * @property {String} content 弹出层显示的内容
| * @property {String} placement出现位置, 目前支持:left right top bottom
| */
| export default {
| name: "uni-tooltip",
| data() {
| return {
|
| };
| },
| methods: {},
| computed: {
| initPlacement() {
| let style = {};
| switch (this.placement) {
| case 'left':
| style = {
| top: '50%',
| transform: 'translateY(-50%)',
| right: '100%',
| "margin-right": '10rpx',
| }
| break;
| case 'right':
| style = {
| top: '50%',
| transform: 'translateY(-50%)',
| left: '100%',
| "margin-left": '10rpx',
| }
| break;
| case 'top':
| style = {
| bottom: '100%',
| transform: 'translateX(-50%)',
| left: '50%',
| "margin-bottom": '10rpx',
| }
| break;
| case 'bottom':
| style = {
| top: '100%',
| transform: 'translateX(-50%)',
| left: '50%',
| "margin-top": '10rpx',
| }
| break;
| }
| return style;
| }
| },
| props: {
| content: {
| type: String,
| default: ''
| },
|
| placement: {
| type: String,
| default: 'bottom'
| },
| }
| }
| </script>
|
| <style>
| .uni-tooltip {
| position: relative;
| cursor: pointer;
| display: inline-block;
| }
|
| .uni-tooltip-popup {
| z-index: 1;
| display: none;
| position: absolute;
| background-color: #333;
| border-radius: 8px;
| color: #fff;
| font-size: 12px;
| text-align: left;
| line-height: 16px;
| padding: 12px;
| overflow: auto;
| }
|
|
| .uni-tooltip:hover .uni-tooltip-popup {
| display: block;
| }
| </style>
|
|