用于標(biāo)記和選擇。
1.如何使用?
由type屬性來(lái)選擇tag的類型,也可以通過(guò)color屬性來(lái)自定義背景色。
<el-tag>標(biāo)簽一</el-tag>
<el-tag type="success">標(biāo)簽二</el-tag>
<el-tag type="info">標(biāo)簽三</el-tag>
<el-tag type="warning">標(biāo)簽四</el-tag>
<el-tag type="danger">標(biāo)簽五</el-tag>
2.可移除標(biāo)簽
//設(shè)置closable屬性可以定義一個(gè)標(biāo)簽是否可移除。默認(rèn)的標(biāo)簽移除時(shí)會(huì)附帶漸變動(dòng)畫,如果不想使用,可以設(shè)置disable-transitions屬性,它接受一個(gè)Boolean,true 為關(guān)閉。
<el-tag
v-for="tag in tags"
:key="tag.name"
closable
:type="tag.type">
{{tag.name}}
</el-tag>
<script>
export default {
data() {
return {
tags: [
{ name: '標(biāo)簽一', type: '' },
{ name: '標(biāo)簽二', type: 'success' },
{ name: '標(biāo)簽三', type: 'info' },
{ name: '標(biāo)簽四', type: 'warning' },
{ name: '標(biāo)簽五', type: 'danger' }
]
};
}
}
</script>
3.?動(dòng)態(tài)編輯標(biāo)簽
動(dòng)態(tài)編輯標(biāo)簽可以通過(guò)點(diǎn)擊標(biāo)簽關(guān)閉按鈕后觸發(fā)的?close
?事件來(lái)實(shí)現(xiàn)
<el-tag
:key="tag"
v-for="tag in dynamicTags"
closable
:disable-transitions="false"
@close="handleClose(tag)">
{{tag}}
</el-tag>
<el-input
class="input-new-tag"
v-if="inputVisible"
v-model="inputValue"
ref="saveTagInput"
size="small"
@keyup.enter.native="handleInputConfirm"
@blur="handleInputConfirm"
>
</el-input>
<el-button v-else class="button-new-tag" size="small" @click="showInput">+ New Tag</el-button>
<style>
.el-tag + .el-tag {
margin-left: 10px;
}
.button-new-tag {
margin-left: 10px;
height: 32px;
line-height: 30px;
padding-top: 0;
padding-bottom: 0;
}
.input-new-tag {
width: 90px;
margin-left: 10px;
vertical-align: bottom;
}
</style>
<script>
export default {
data() {
return {
dynamicTags: ['標(biāo)簽一', '標(biāo)簽二', '標(biāo)簽三'],
inputVisible: false,
inputValue: ''
};
},
methods: {
handleClose(tag) {
this.dynamicTags.splice(this.dynamicTags.indexOf(tag), 1);
},
showInput() {
this.inputVisible = true;
this.$nextTick(_ => {
this.$refs.saveTagInput.$refs.input.focus();
});
},
handleInputConfirm() {
let inputValue = this.inputValue;
if (inputValue) {
this.dynamicTags.push(inputValue);
}
this.inputVisible = false;
this.inputValue = '';
}
}
}
</script>
4.不同尺寸
Tag 組件提供除了默認(rèn)值以外的三種尺寸,可以在不同場(chǎng)景下選擇合適的按鈕尺寸。
額外的尺寸:medium、small、mini,通過(guò)設(shè)置size屬性來(lái)配置它們。
<el-tag closable>默認(rèn)標(biāo)簽</el-tag>
<el-tag size="medium" closable>中等標(biāo)簽</el-tag>
<el-tag size="small" closable>小型標(biāo)簽</el-tag>
<el-tag size="mini" closable>超小標(biāo)簽</el-tag>
5.不同主題
Tag 組件提供了三個(gè)不同的主題:dark
、light
?和?plain
文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-692100.html
通過(guò)設(shè)置effect屬性來(lái)改變主題,默認(rèn)為 light
<div class="tag-group">
<span class="tag-group__title">Dark</span>
<el-tag
v-for="item in items"
:key="item.label"
:type="item.type"
effect="dark">
{{ item.label }}
</el-tag>
</div>
<div class="tag-group">
<span class="tag-group__title">Plain</span>
<el-tag
v-for="item in items"
:key="item.label"
:type="item.type"
effect="plain">
{{ item.label }}
</el-tag>
</div>
<script>
export default {
data() {
return {
items: [
{ type: '', label: '標(biāo)簽一' },
{ type: 'success', label: '標(biāo)簽二' },
{ type: 'info', label: '標(biāo)簽三' },
{ type: 'danger', label: '標(biāo)簽四' },
{ type: 'warning', label: '標(biāo)簽五' }
]
}
}
}
</script>
?文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-692100.html
到了這里,關(guān)于ElementUI淺嘗輒止16:Tag 標(biāo)簽的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!