From dc39cc3163382062511f05f015d90b748df33758 Mon Sep 17 00:00:00 2001 From: daiyanze Date: Wed, 18 Oct 2017 17:13:06 +0900 Subject: [PATCH] Feature: Checkable tag --- examples/routers/tag.vue | 11 ++++++++--- src/components/tag/tag.vue | 34 ++++++++++++++++++++++++++++------ 2 files changed, 36 insertions(+), 9 deletions(-) diff --git a/examples/routers/tag.vue b/examples/routers/tag.vue index 645170c..09801cb 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 1be1311..1984e69 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); } } } -- libgit2 0.21.4