2016-07-27 14:15:02 +08:00
|
|
|
|
<script>
|
|
|
|
|
export default {
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
|
|
|
|
tags: [
|
|
|
|
|
{ key: 1, name: '标签一', type: '' },
|
|
|
|
|
{ key: 2, name: '标签二', type: 'gray' },
|
|
|
|
|
{ key: 5, name: '标签三', type: 'primary' },
|
|
|
|
|
{ key: 3, name: '标签四', type: 'success' },
|
|
|
|
|
{ key: 4, name: '标签五', type: 'warning' },
|
|
|
|
|
{ key: 6, name: '标签六', type: 'danger' }
|
|
|
|
|
]
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
|
|
|
|
handleClose(tag) {
|
2016-07-29 16:41:14 +08:00
|
|
|
|
this.tags.splice(this.tags.indexOf(tag), 1);
|
2016-07-27 14:15:02 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style>
|
|
|
|
|
.demo-box.demo-tag {
|
|
|
|
|
.el-tag + .el-tag {
|
|
|
|
|
margin-left: 10px;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</style>
|
|
|
|
|
|
2016-08-26 18:34:54 +08:00
|
|
|
|
## Tag 标签
|
|
|
|
|
用于标记和选择
|
|
|
|
|
|
|
|
|
|
### 基础使用
|
2016-07-27 14:15:02 +08:00
|
|
|
|
|
2016-08-25 18:24:51 +08:00
|
|
|
|
Tag 组件提供了六种主题。
|
2016-08-18 17:29:11 +08:00
|
|
|
|
|
2016-08-25 18:24:51 +08:00
|
|
|
|
:::demo 由`type`属性来定义,该属性可选填。
|
2016-07-27 14:15:02 +08:00
|
|
|
|
|
|
|
|
|
```html
|
|
|
|
|
<el-tag>标签一</el-tag>
|
|
|
|
|
<el-tag type="gray">标签二</el-tag>
|
|
|
|
|
<el-tag type="primary">标签三</el-tag>
|
|
|
|
|
<el-tag type="success">标签四</el-tag>
|
|
|
|
|
<el-tag type="warning">标签五</el-tag>
|
|
|
|
|
<el-tag type="danger">标签六</el-tag>
|
|
|
|
|
```
|
2016-08-25 18:24:51 +08:00
|
|
|
|
:::
|
2016-07-27 14:15:02 +08:00
|
|
|
|
|
2016-08-26 18:34:54 +08:00
|
|
|
|
### 描边
|
2016-08-18 17:29:11 +08:00
|
|
|
|
|
2016-08-25 18:24:51 +08:00
|
|
|
|
借此可以定义 hover 时的效果。
|
2016-08-18 17:29:11 +08:00
|
|
|
|
|
2016-08-25 18:24:51 +08:00
|
|
|
|
:::demo `hit`属性可以设置描边。
|
2016-08-18 17:29:11 +08:00
|
|
|
|
```html
|
|
|
|
|
<el-tag type="primary" :hit="true">标签</el-tag>
|
|
|
|
|
```
|
2016-08-25 18:24:51 +08:00
|
|
|
|
:::
|
2016-08-18 17:29:11 +08:00
|
|
|
|
|
2016-08-26 18:34:54 +08:00
|
|
|
|
### 可移除的标签
|
2016-07-27 14:15:02 +08:00
|
|
|
|
|
2016-08-25 18:24:51 +08:00
|
|
|
|
:::demo 设置`closable`属性来定义一个可移除的标签,接受一个`Boolean`,设置为`true`即可。默认的标签移除时会附带渐变动画,如果不想使用,可以设置`close-transition`属性,它接受一个`Boolean`,true 为关闭。设置`close`事件可以处理关闭后的回调函数。
|
2016-07-27 14:15:02 +08:00
|
|
|
|
|
|
|
|
|
```html
|
|
|
|
|
<el-tag
|
|
|
|
|
v-for="tag in tags"
|
|
|
|
|
:closable="true"
|
|
|
|
|
:type="tag.type"
|
2016-08-18 17:29:11 +08:00
|
|
|
|
:key="tag"
|
|
|
|
|
:close-transition="false"
|
2016-07-27 14:15:02 +08:00
|
|
|
|
@close="handleClose(tag)"
|
|
|
|
|
>
|
|
|
|
|
{{tag.name}}
|
|
|
|
|
</el-tag>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
export default {
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
|
|
|
|
tags: [
|
|
|
|
|
{ key: 1, name: '标签一', type: '' },
|
|
|
|
|
{ key: 2, name: '标签二', type: 'gray' },
|
|
|
|
|
{ key: 5, name: '标签三', type: 'primary' },
|
|
|
|
|
{ key: 3, name: '标签四', type: 'success' },
|
|
|
|
|
{ key: 4, name: '标签五', type: 'warning' },
|
|
|
|
|
{ key: 6, name: '标签六', type: 'danger' }
|
|
|
|
|
]
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
|
|
|
|
handleClose(tag) {
|
|
|
|
|
this.tags.$remove(tag);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
```
|
2016-08-25 18:24:51 +08:00
|
|
|
|
:::
|
2016-08-18 17:29:11 +08:00
|
|
|
|
|
2016-08-26 18:34:54 +08:00
|
|
|
|
### Attributes
|
2016-08-18 17:29:11 +08:00
|
|
|
|
| 参数 | 说明 | 类型 | 可选值 | 默认值 |
|
|
|
|
|
|---------- |-------------- |---------- |-------------------------------- |-------- |
|
|
|
|
|
| type | 主题 | string | 'primary', 'gray', 'success', 'warning', 'error' | |
|
|
|
|
|
| closable | 是否可关闭 | boolean | | false |
|
|
|
|
|
| close-transition | 是否禁用关闭时的渐变动画 | boolean | | false |
|
|
|
|
|
| hit | 是否有边框描边 | boolean | | false |
|
|
|
|
|
|
|
|
|
|
|
2016-08-26 18:34:54 +08:00
|
|
|
|
### Events
|
2016-08-18 17:29:11 +08:00
|
|
|
|
| 事件名称 | 说明 | 回调参数 |
|
|
|
|
|
|---------- |-------- |---------- |
|
|
|
|
|
| close | 关闭tag时触发的事件 | |
|