mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
done
This commit is contained in:
parent
04712433c0
commit
ba405b723b
@ -5,10 +5,10 @@
|
|||||||
:::demo 样例代码
|
:::demo 样例代码
|
||||||
```html
|
```html
|
||||||
<z-badge-group>
|
<z-badge-group>
|
||||||
<z-badge is-selected value="热销榜" info="8"></z-badge>
|
<z-badge badge-key="0" title="热销榜" info="8"></z-badge>
|
||||||
<z-badge value="花式寿司" info="99"></z-badge>
|
<z-badge badge-key="1" title="花式寿司" info="99"></z-badge>
|
||||||
<z-badge value="火炽寿司"></z-badge>
|
<z-badge badge-key="2" title="火炽寿司"></z-badge>
|
||||||
<z-badge value="手握寿司" info="199"></z-badge>
|
<z-badge badge-key="3" title="手握寿司" info="199"></z-badge>
|
||||||
</z-badge-group>
|
</z-badge-group>
|
||||||
```
|
```
|
||||||
:::
|
:::
|
34
packages/badge/mixin/emitter.js
Normal file
34
packages/badge/mixin/emitter.js
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
@ -6,6 +6,11 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
export default {
|
export default {
|
||||||
name: 'z-badge-group'
|
name: 'z-badge-group',
|
||||||
|
data () {
|
||||||
|
return {
|
||||||
|
activeKey: '0'
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
@ -1,22 +1,41 @@
|
|||||||
<template>
|
<template>
|
||||||
<a class="z-badge" :class="{ 'is-select' : isSelected }" :href="url" @click="handleClick">
|
<a class="z-badge" :class="classNames" :href="url" @click="handleClick">
|
||||||
<div class="z-badge__active"></div>
|
<div class="z-badge__active"></div>
|
||||||
<div v-if="info" class="z-badge__info">{{info}}</div>
|
<div v-if="info" class="z-badge__info">{{info}}</div>
|
||||||
{{value}}
|
{{title}}
|
||||||
</a>
|
</a>
|
||||||
</template>
|
</template>
|
||||||
<script>
|
<script>
|
||||||
export default {
|
export default {
|
||||||
name: 'z-badge',
|
name: 'z-badge',
|
||||||
props: {
|
props: {
|
||||||
|
badgeKey: {
|
||||||
|
type: [Number, String],
|
||||||
|
required: true
|
||||||
|
},
|
||||||
|
title: {
|
||||||
|
type: String,
|
||||||
|
required: true
|
||||||
|
},
|
||||||
url: String,
|
url: String,
|
||||||
value: String,
|
value: String,
|
||||||
info: String,
|
info: String
|
||||||
isSelected: Boolean
|
},
|
||||||
|
data () {
|
||||||
|
return {
|
||||||
|
isSelected: false
|
||||||
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
handleClick() {
|
handleClick() {
|
||||||
this.$emit('click');
|
this.$parent.activeKey = this.badgeKey;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
classNames () {
|
||||||
|
return {
|
||||||
|
'is-select': this.badgeKey == this.$parent.activeKey ? true : false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user