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-09-08 09:15:35 +08:00
|
|
|
|
用于标记和选择。
|
|
|
|
|
|
|
|
|
|
### 基础用法
|
2016-07-27 14:15:02 +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-09-08 09:15:35 +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
|
|
|
|
| 参数 | 说明 | 类型 | 可选值 | 默认值 |
|
|
|
|
|
|---------- |-------------- |---------- |-------------------------------- |-------- |
|
2016-09-02 13:56:47 +08:00
|
|
|
|
| type | 主题 | string | 'primary', 'gray', 'success', 'warning', 'error' | — |
|
|
|
|
|
| closable | 是否可关闭 | boolean | — | false |
|
|
|
|
|
| close-transition | 是否禁用关闭时的渐变动画 | boolean | — | false |
|
|
|
|
|
| hit | 是否有边框描边 | boolean | — | false |
|
2016-08-18 17:29:11 +08:00
|
|
|
|
|
|
|
|
|
|
2016-08-26 18:34:54 +08:00
|
|
|
|
### Events
|
2016-08-18 17:29:11 +08:00
|
|
|
|
| 事件名称 | 说明 | 回调参数 |
|
|
|
|
|
|---------- |-------- |---------- |
|
2016-09-02 13:56:47 +08:00
|
|
|
|
| close | 关闭tag时触发的事件 | — |
|