This commit is contained in:
zhuxiang
2017-03-01 14:28:10 +08:00
parent ba405b723b
commit 0abb184056
4 changed files with 32 additions and 50 deletions

View File

@@ -1,34 +0,0 @@
function broadcast(componentName, eventName, ...params) {
this.$children.forEach(child => {
var name = child.$options.componentName;
if (name === componentName) {
child.$emit.apply(child, [eventName].concat(params));
} else {
broadcast.apply(child, [componentName, eventName].concat(params));
}
});
}
export default {
methods: {
$dispatch(componentName, eventName, ...params) {
var parent = this.$parent || this.$root;
var name = parent.$options.componentName;
while (parent && (!name || name !== componentName)) {
parent = parent.$parent;
if (parent) {
name = parent.$options.componentName;
}
}
if (parent) {
parent.$emit.apply(parent, [eventName].concat(params));
}
},
$broadcast(componentName, eventName, ...params) {
broadcast.call(this, componentName, eventName, ...params);
}
}
};

View File

@@ -7,9 +7,16 @@
<script>
export default {
name: 'z-badge-group',
props: {
// 当前激活 tab 面板的 key
activeKey: {
type: [Number, String],
default: 0
}
},
data () {
return {
activeKey: '0'
computedActiveKey: this.activeKey
}
}
};

View File

@@ -9,7 +9,7 @@
export default {
name: 'z-badge',
props: {
badgeKey: {
mark: {
type: [Number, String],
required: true
},
@@ -18,23 +18,17 @@ export default {
required: true
},
url: String,
value: String,
info: String
},
data () {
return {
isSelected: false
}
},
methods: {
handleClick() {
this.$parent.activeKey = this.badgeKey;
this.$parent.computedActiveKey = this.mark;
}
},
computed: {
classNames () {
return {
'is-select': this.badgeKey == this.$parent.activeKey ? true : false
'is-select': this.mark == this.$parent.computedActiveKey ? true : false
}
}
}