mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
45 lines
791 B
Vue
45 lines
791 B
Vue
<template>
|
|
<a :class="['van-badge', { 'van-badge--select': isSelect }]" :href="url" @click="onClick">
|
|
<div class="van-badge__active"></div>
|
|
<div v-if="info" class="van-badge__info">{{ info }}</div>
|
|
{{ title }}
|
|
</a>
|
|
</template>
|
|
|
|
<script>
|
|
export default {
|
|
name: 'van-badge',
|
|
|
|
props: {
|
|
title: {
|
|
type: String,
|
|
required: true
|
|
},
|
|
url: {
|
|
type: String,
|
|
default: 'javascript:;'
|
|
},
|
|
info: {
|
|
type: String
|
|
}
|
|
},
|
|
|
|
beforeCreate() {
|
|
this.$parent.badges.push(this);
|
|
},
|
|
|
|
computed: {
|
|
isSelect() {
|
|
const parent = this.$parent;
|
|
return parent.badges.indexOf(this) === parent.activeKey;
|
|
}
|
|
},
|
|
|
|
methods: {
|
|
onClick() {
|
|
this.$emit('click', this.$parent.badges.indexOf(this));
|
|
}
|
|
}
|
|
};
|
|
</script>
|