diff --git a/examples/routers/tag.vue b/examples/routers/tag.vue index 645170c6..09801cb5 100644 --- a/examples/routers/tag.vue +++ b/examples/routers/tag.vue @@ -1,6 +1,7 @@ @@ -9,13 +10,17 @@ data () { return { count: 3 - } + }; }, methods: { close (e, name) { console.log(e); console.log(name); + }, + check (e, name) { + console.log(e); + console.log(name); } } - } + }; diff --git a/src/components/tag/tag.vue b/src/components/tag/tag.vue index 1be13116..1984e69f 100644 --- a/src/components/tag/tag.vue +++ b/src/components/tag/tag.vue @@ -1,7 +1,8 @@ @@ -19,6 +20,14 @@ type: Boolean, default: false }, + checkable: { + type: Boolean, + default: false + }, + checked: { + type: Boolean, + default: true + }, color: { validator (value) { return oneOf(value, ['blue', 'green', 'red', 'yellow', 'default']); @@ -33,14 +42,20 @@ type: [String, Number] } }, + data () { + return { + isChecked: this.checked + }; + }, computed: { classes () { return [ `${prefixCls}`, { - [`${prefixCls}-${this.color}`]: !!this.color, + [`${prefixCls}-${this.color}`]: !!this.color && (this.checkable && this.isChecked), [`${prefixCls}-${this.type}`]: !!this.type, - [`${prefixCls}-closable`]: this.closable + [`${prefixCls}-closable`]: this.closable, + [`${prefixCls}-checkable`]: this.checkable } ]; }, @@ -56,10 +71,17 @@ }, methods: { close (event) { + this._emitAction(event, 'on-close'); + }, + check (event) { + this.isChecked = !this.isChecked; + this._emitAction(event, 'on-check'); + }, + _emitAction (event, action) { if (this.name === undefined) { - this.$emit('on-close', event); + this.$emit(action, event); } else { - this.$emit('on-close', event, this.name); + this.$emit(action, event, this.name); } } }