clock-shop/source/src/components/Btn.vue
a-jie d79a4c25c7 add source
add source
2018-06-14 21:41:36 +08:00

48 lines
851 B
Vue

<template>
<li class="nbtn"
@click="click()"
v-bind:class="{ 'btn-active' : isActive}"
>
<slot></slot>
</li>
</template>
<script>
import ppo from 'ppo';
import Vue from 'vue';
const bus = new Vue();
export default {
name: 'Btn',
props: ['active'],
created: function () {
bus.$on('BTN_CLICK', id => {
if (id !== this.id) {
this.isActive = false;
}
});
if(this.active){
this.isActive = true;
}
},
data() {
return {
id: ppo.uuid(),
isActive: false
}
},
methods: {
click() {
this.isActive = true;
bus.$emit('BTN_CLICK', this.id);
}
}
}
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
</style>