1.0.0 • Published 8 years ago

vue-count-button v1.0.0

Weekly downloads
3
License
MIT
Repository
github
Last release
8 years ago

vue-count-button

NPM version

A simple vue component that count the clicking times

Try online demo here: demonstration

Installation

via npm

npm install vue-count-button --save

Import

ES2015

import VueCountButton from 'vue-count-button';

CommonJS

var VueCountButton = require('vue-count-button');

script

<script type="text/javascript" src="vue/dist/vue.min.js"></script>
<script type="text/javascript" src="vue-count-button/dist/vue-count-button.js"></script>
<script type="text/javascript">
    var VueCountButton = window['vue-count-button'];
</script>

Basic Usage

<vue-count-button v-on:counter-updated="onChange"></vue-count-button>
new Vue({
    el: 'body',
    components: {
        'vue-count-button': VueCountButton
    },
    methods: {
        onChange: function(e){
            console.log(e); //e is current counter value
        }
    }
});

Props

NameTypeRequiredDescriptionExample
initnumberNoThe initial value of the counter. 0 by default5
txtstringNoThe text displayed in center of the counter. OK by default'Push'
widthnumberNoThe width of the counter. 50 by default70
bgColorstringNoThe background-color of the counter. #464646 by default | green

Events

NameTypeRequiredDescription
counter-updatedin -> outNoGet notified while counter is updated.
counter-resetout -> inNoNotify the counter to be reset.

Examples

Event - counter-updated

<vue-count-button v-on:counter-updated="onChange"></vue-count-button>
new Vue({
    ...
    components: {
        'vue-count-button': VueCountButton
    },
    methods: {
        onChange: function(e){
            console.log(e); //e is current counter value
        }
    }
});

Event - counter-reset

<vue-count-button v-ref:count></vue-count-button>
new Vue({
    ...
    components: {
        'vue-count-button': VueCountButton
    },
    created: function() {
        setTimeout(() => {
            //the counter will be reset from 20
            this.$refs.count.$emit('counter-reset', 20);
        }, 1000);
    }
});

LICENSE

MIT License