vant/packages/badge/src/badge.vue
张敏 0f5972e75e 支持SSR、升级Vue版本和增加新的icon (#40)
* search component add new style

* update vue version and support ssr

* unit test

* add new icon

* new icon
2017-06-15 19:46:56 +08:00

53 lines
886 B
Vue

<template>
<a
class="van-badge"
:class="{ 'van-badge--select': isSelect }"
:href="url"
@click="handleClick">
<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: {
handleClick(e) {
this.$emit('click', e, {
title: this.title,
url: this.url,
info: this.info
});
}
}
};
</script>