2016-08-18 17:29:11 +08:00
|
|
|
|
<script>
|
|
|
|
|
export default {
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
|
|
|
|
disabled: false
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
</script>
|
2016-08-26 18:34:54 +08:00
|
|
|
|
## Tooltips 文字提示
|
2016-08-18 17:29:11 +08:00
|
|
|
|
|
2016-08-26 18:34:54 +08:00
|
|
|
|
### 基础用法
|
2016-08-18 17:29:11 +08:00
|
|
|
|
|
2016-08-26 18:34:54 +08:00
|
|
|
|
Tooltip 组件常用于展示鼠标 hover 时的提示信息,在这里我们提供9种不同的展示方式。
|
2016-08-18 17:29:11 +08:00
|
|
|
|
|
2016-08-26 18:34:54 +08:00
|
|
|
|
下面是完整的九个示例,可以通过该示例来理解,选择你要的效果:
|
2016-08-18 17:29:11 +08:00
|
|
|
|
|
2016-08-26 18:34:54 +08:00
|
|
|
|
:::demo 使用`content`属性来决定`hover`时的提示信息。由`placement`属性决定展示效果:`placement`属性值为:`方向-箭头方位`;四个方向:`top`、`left`、`right`、`bottom`;三种箭头方位:`start`, `end`,默认为空。如`top center`即`placement="top"`,`left top`即`placement="left-end"`。
|
2016-07-27 14:15:02 +08:00
|
|
|
|
|
2016-08-26 18:34:54 +08:00
|
|
|
|
```html
|
2016-07-27 14:15:02 +08:00
|
|
|
|
<style>
|
|
|
|
|
.box {
|
|
|
|
|
width: 400px;
|
|
|
|
|
|
|
|
|
|
.top {
|
|
|
|
|
text-align: center;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.left {
|
|
|
|
|
float: left;
|
|
|
|
|
width: 60px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.right {
|
|
|
|
|
float: right;
|
|
|
|
|
width: 60px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.bottom {
|
|
|
|
|
clear: both;
|
|
|
|
|
text-align: center;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.item {
|
|
|
|
|
margin: 4px;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</style>
|
|
|
|
|
|
|
|
|
|
<div class="box">
|
|
|
|
|
<div class="top">
|
2016-08-23 13:29:45 +08:00
|
|
|
|
<el-tooltip class="item" effect="dark" content="Top Left 提示文字" placement="top-end">
|
2016-07-27 14:15:02 +08:00
|
|
|
|
<el-button>上左</el-button>
|
|
|
|
|
</el-tooltip>
|
2016-08-05 17:02:01 +08:00
|
|
|
|
<el-tooltip class="item" effect="dark" content="Top Center 提示文字" placement="top">
|
2016-07-27 14:15:02 +08:00
|
|
|
|
<el-button>上边</el-button>
|
|
|
|
|
</el-tooltip>
|
2016-08-23 13:29:45 +08:00
|
|
|
|
<el-tooltip class="item" effect="dark" content="Top Right 提示文字" placement="top-start">
|
2016-07-27 14:15:02 +08:00
|
|
|
|
<el-button>上右</el-button>
|
|
|
|
|
</el-tooltip>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="left">
|
2016-08-23 13:29:45 +08:00
|
|
|
|
<el-tooltip class="item" effect="dark" content="Left Top 提示文字" placement="left-end">
|
2016-07-27 14:15:02 +08:00
|
|
|
|
<el-button>左上</el-button>
|
|
|
|
|
</el-tooltip>
|
2016-08-05 17:02:01 +08:00
|
|
|
|
<el-tooltip class="item" effect="dark" content="Left Center 提示文字" placement="left">
|
2016-07-27 14:15:02 +08:00
|
|
|
|
<el-button>左边</el-button>
|
|
|
|
|
</el-tooltip>
|
2016-08-23 13:29:45 +08:00
|
|
|
|
<el-tooltip class="item" effect="dark" content="Left Bottom 提示文字" placement="left-start">
|
2016-07-27 14:15:02 +08:00
|
|
|
|
<el-button>左下</el-button>
|
|
|
|
|
</el-tooltip>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="right">
|
2016-08-23 13:29:45 +08:00
|
|
|
|
<el-tooltip class="item" effect="dark" content="Right Top 提示文字" placement="right-end">
|
2016-07-27 14:15:02 +08:00
|
|
|
|
<el-button>右上</el-button>
|
|
|
|
|
</el-tooltip>
|
2016-08-05 17:02:01 +08:00
|
|
|
|
<el-tooltip class="item" effect="dark" content="Right Center 提示文字" placement="right">
|
2016-07-27 14:15:02 +08:00
|
|
|
|
<el-button>右边</el-button>
|
|
|
|
|
</el-tooltip>
|
2016-08-23 13:29:45 +08:00
|
|
|
|
<el-tooltip class="item" effect="dark" content="Right Bottom 提示文字" placement="right-start">
|
2016-07-27 14:15:02 +08:00
|
|
|
|
<el-button>右下</el-button>
|
|
|
|
|
</el-tooltip>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="bottom">
|
2016-08-23 13:29:45 +08:00
|
|
|
|
<el-tooltip class="item" effect="dark" content="Bottom Left 提示文字" placement="bottom-end">
|
2016-07-27 14:15:02 +08:00
|
|
|
|
<el-button>下左</el-button>
|
|
|
|
|
</el-tooltip>
|
2016-08-05 17:02:01 +08:00
|
|
|
|
<el-tooltip class="item" effect="dark" content="Bottom Center 提示文字" placement="bottom">
|
2016-07-27 14:15:02 +08:00
|
|
|
|
<el-button>下边</el-button>
|
|
|
|
|
</el-tooltip>
|
2016-08-23 13:29:45 +08:00
|
|
|
|
<el-tooltip class="item" effect="dark" content="Bottom Right 提示文字" placement="bottom-start">
|
2016-07-27 14:15:02 +08:00
|
|
|
|
<el-button>下右</el-button>
|
|
|
|
|
</el-tooltip>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2016-08-26 18:34:54 +08:00
|
|
|
|
```
|
|
|
|
|
:::
|
2016-07-27 14:15:02 +08:00
|
|
|
|
|
2016-08-26 18:34:54 +08:00
|
|
|
|
### 主题
|
2016-07-27 14:15:02 +08:00
|
|
|
|
|
2016-08-26 18:34:54 +08:00
|
|
|
|
Tooltip 组件提供了两个不同的主题:`dark`和`light`。
|
2016-07-27 14:15:02 +08:00
|
|
|
|
|
|
|
|
|
|
2016-08-26 18:34:54 +08:00
|
|
|
|
:::demo 通过设置`effect`属性来改变主题,默认为`dark`。
|
2016-08-18 17:29:11 +08:00
|
|
|
|
```html
|
|
|
|
|
<el-tooltip content="Top center" placement="top">
|
|
|
|
|
<el-button>Dark</el-button>
|
|
|
|
|
</el-tooltip>
|
|
|
|
|
<el-tooltip content="Bottom center" placement="bottom" effect="light">
|
|
|
|
|
<el-button>Light</el-button>
|
|
|
|
|
</el-tooltip>
|
|
|
|
|
```
|
2016-08-26 18:34:54 +08:00
|
|
|
|
:::
|
2016-08-18 17:29:11 +08:00
|
|
|
|
|
2016-08-26 18:34:54 +08:00
|
|
|
|
### 更多Content
|
2016-08-18 17:29:11 +08:00
|
|
|
|
|
2016-08-26 18:34:54 +08:00
|
|
|
|
展示多行文本或者是设置文本内容的格式
|
2016-08-18 17:29:11 +08:00
|
|
|
|
|
2016-08-26 18:34:54 +08:00
|
|
|
|
:::demo 用具名 slot 分发`content`,替代`tooltip`中的`content`属性。
|
2016-08-18 17:29:11 +08:00
|
|
|
|
```html
|
|
|
|
|
<el-tooltip placement="top">
|
|
|
|
|
<div slot="content">多行信息<br/>第二行信息</div>
|
|
|
|
|
<el-button>Top center</el-button>
|
|
|
|
|
</el-tooltip>
|
|
|
|
|
```
|
2016-08-26 18:34:54 +08:00
|
|
|
|
:::
|
2016-08-18 17:29:11 +08:00
|
|
|
|
|
2016-08-26 18:34:54 +08:00
|
|
|
|
### 高级扩展
|
2016-08-18 17:29:11 +08:00
|
|
|
|
|
|
|
|
|
除了这些基本设置外,还有一些属性可以让使用者更好的定制自己的效果:
|
|
|
|
|
|
|
|
|
|
`transition`属性可以定制显隐的动画效果,默认为`fade-in-linear`。
|
|
|
|
|
|
|
|
|
|
如果需要关闭`tooltip`功能,`disabled`属性可以满足这个需求,它接受一个`Boolean`,设置为`true`即可。
|
|
|
|
|
|
2016-08-30 19:06:15 +08:00
|
|
|
|
事实上,这是基于 [Vue-popper](https://github.com/element-component/vue-popper) 的扩展,你可以自定义任意 Vue-popper 中允许定义的字段。
|
2016-08-18 17:29:11 +08:00
|
|
|
|
|
|
|
|
|
当然,Tooltip 组件实际上十分强大,文末的API文档会做一一说明。
|
|
|
|
|
|
2016-08-26 18:34:54 +08:00
|
|
|
|
:::demo
|
2016-08-18 17:29:11 +08:00
|
|
|
|
```html
|
2016-08-19 14:45:08 +08:00
|
|
|
|
<template>
|
2016-08-30 19:06:15 +08:00
|
|
|
|
<el-tooltip :disabled="disabled" content="点击关闭 tooltip 功能" placement="bottom" effect="light">
|
2016-08-19 14:45:08 +08:00
|
|
|
|
<el-button @click.native="disabled=true">点击关闭 tooltip 功能</el-button>
|
|
|
|
|
</el-tooltip>
|
|
|
|
|
</template>
|
2016-08-18 17:29:11 +08:00
|
|
|
|
|
|
|
|
|
<style>
|
|
|
|
|
.slide-fade-enter-active {
|
|
|
|
|
transition: all .3s ease;
|
|
|
|
|
}
|
|
|
|
|
.slide-fade-leave-active {
|
|
|
|
|
transition: all .3s cubic-bezier(1.0, 0.5, 0.8, 1.0);
|
|
|
|
|
}
|
|
|
|
|
.slide-fade-enter, .expand-fade-leave-active {
|
|
|
|
|
margin-left: 20px;
|
|
|
|
|
opacity: 0;
|
|
|
|
|
}
|
|
|
|
|
</style>
|
|
|
|
|
```
|
2016-08-26 18:34:54 +08:00
|
|
|
|
:::
|
2016-08-18 17:29:11 +08:00
|
|
|
|
|
2016-08-26 18:34:54 +08:00
|
|
|
|
### Attributes
|
2016-07-27 14:15:02 +08:00
|
|
|
|
| 参数 | 说明 | 类型 | 可选值 | 默认值 |
|
|
|
|
|
|--------------------|----------------------------------------------------------|-------------------|-------------|--------|
|
2016-08-18 17:29:11 +08:00
|
|
|
|
| effect | 默认提供的主题 | String | `dark`, `light` | dark |
|
2016-09-02 13:56:47 +08:00
|
|
|
|
| content | 显示的内容,也可以通过 `slot#content` 传入 DOM | String | — | — |
|
2016-08-18 17:29:11 +08:00
|
|
|
|
| placement | Tooltip 的出现位置 | String | `top`, `top-start`, `top-end`, `bottom`, `bottom-start`, `bottom-end`, `left`, `left-start`, `left-end`, `right`, `right-start`, `right-end` | bottom |
|
2016-09-02 19:32:17 +08:00
|
|
|
|
| value(v-model) | 状态是否可见 | Boolean | — | false |
|
2016-09-02 13:56:47 +08:00
|
|
|
|
| disabled | Tooltip 是否可用 | Boolean | — | false |
|
|
|
|
|
| offset | 出现位置的偏移量 | Number | — | 0 |
|
|
|
|
|
| transition | 定义渐变动画 | String | — | `fade-in-linear` |
|
|
|
|
|
| visible-arrow | 是否显示 Tooltip 箭头,更多参数可见[Vue-popper](https://github.com/element-component/vue-popper) | Boolean | — | true |
|
2016-08-18 17:29:11 +08:00
|
|
|
|
| options | [popper.js](https://popper.js.org/documentation.html) 的参数 | Object | 参考 [popper.js](https://popper.js.org/documentation.html) 文档 | `{ boundariesElement: 'body', gpuAcceleration: false }` |
|
2016-09-02 13:56:47 +08:00
|
|
|
|
| openDelay | 延迟出现,单位毫秒 | Number | — | 0 |
|