https://element.eleme.io/#/zh-CN/component/tag
<el-tag>标签一el-tag>
边框描边由hit
属性指定
<h1>边框描边h1>
<el-tag :hit="true">有边框描边el-tag>
<el-tag :hit="false">无边框描边el-tag>
情境色由type
属性指定,做了两件事:
success
info
warning
danger
<h1>情境色h1>
<el-tag type="success">标签一el-tag>
<el-tag type="info">标签二el-tag>
<el-tag type="warning">标签三el-tag>
<el-tag type="danger">标签四el-tag>
主题由effect
属性指定
dark
light
plain
<h1>主题h1>
<el-tag type="success" effect="dark">标签一el-tag>
<el-tag type="warning" effect="light">标签二el-tag>
<el-tag type="danger" effect="plain">标签三el-tag>
背景颜色可以由color
属性自行指定,但不会覆盖type的边框色
<h1>自定义背景颜色h1>
<h2>color覆盖type的背景色,但不会覆盖type的边框色h2>
<el-tag color="pink" effect="dark" type="success">标签一el-tag>
<el-tag color="red" effect="light" type="warning">标签二el-tag>
<el-tag color="green" effect="plain" type="danger">标签三el-tag>
尺寸由size
属性指定
medium
small
mini
<h1>尺寸h1>
<el-tag effect="light" type="success">正常el-tag>
<el-tag effect="light" type="success" size="medium">Mediumel-tag>
<el-tag effect="light" type="success" size="small">Smallel-tag>
<el-tag effect="light" type="success" size="mini">Miniel-tag>
closable
是显示关闭按钮close
事件disable-transitions
属性可以指定是否禁用渐变动画v-if
<p>
<el-tag v-if="isShow" closable @close="handleClose" :disable-transitions="false">标签一el-tag>
p>
handleClose() {
// 第一种方法
this.isShow = false;
},
dom
<p>
<el-tag closable @close="handleClose2" :disable-transitions="false">标签二el-tag>
p>
handleClose2() {
// 第二种方法
console.log(event);
console.log(event.path[1]);
event.path[1].style.display = 'none';
},
v-for
<el-tag
closable
@close="handleClose3(index)"
:disable-transitions="false"
v-for="(tag, index) in dynamicTags"
:key="index"
>{{tag}}el-tag>
<script>
export default {
data() {
return {
dynamicTags: ['标签一', '标签二', '标签三'],
}
},
methods: {
handleClose4(tag) {
this.dynamicTags2.splice(this.dynamicTags2.indexOf(tag), 1);
},
}
}
</script>
<h1>click事件h1>
<p>
<el-tag @click="handleClick">Click事件el-tag>
p>
handleClick() {
console.log('点我啦');
},
<el-tag
:key="tag"
v-for="tag in dynamicTags2"
closable
:disable-transitions="false"
@close="handleClose4(tag)">
{{tag}}
el-tag>
<el-input
class="input-new-tag"
size="small"
ref="saveTagInput"
v-model="inputValue"
v-if="inputVisible"
@keyup.enter.native="handleInputConfirm"
@blur="handleInputConfirm">
el-input>
<el-button class="button-new-tag" v-else @click="showInput" size="small">+ New Tagel-button>
<script>
export default {
data() {
return {
dynamicTags2: ['标签一', '标签二', '标签三'],
inputVisible: false,
inputValue: '',
}
},
methods: {
handleClose4(tag) {
this.dynamicTags2.splice(this.dynamicTags2.indexOf(tag), 1);
},
showInput() {
this.inputVisible = true;
this.$nextTick(_ => {
this.$refs.saveTagInput.$refs.input.focus();
})
},
handleInputConfirm() {
let inputVal = this.inputValue;
if (inputVal) {
this.dynamicTags2.push(inputVal)
}
this.inputValue = '';
this.inputVisible = false;
},
}
}
</script>
参数 | 说明 | 类型 | 可选值 | 默认值 |
---|---|---|---|---|
type | 类型 | string | success/info/warning/danger | — |
closable | 是否可关闭 | boolean | — | false |
disable-transitions | 是否禁用渐变动画 | boolean | — | false |
hit | 是否有边框描边 | boolean | — | false |
color | 背景色 | string | — | — |
size | 尺寸 | string | medium / small / mini | — |
effect | 主题 | string | dark / light / plain | light |
事件名称 | 说明 | 回调参数 |
---|---|---|
click | 点击 Tag 时触发的事件 | — |
close | 关闭 Tag 时触发的事件 | — |