组件用.vue还是.js_用Vue.js 2制作的类似Twitter的投票组件

组件用.vue还是.js

投票 (Vue-poll)

A Vue.js component for voting.

用于投票的Vue.js组件。

vue-poll-example

先决条件 (Prerequisites)

  • Vue.js 2

    Vue.js 2

正在安装 (Installing)

Using npm:

使用npm:

$ npm install vue-poll

Using cdn:

使用cdn:

<script src="https://unpkg.com/vue-poll/dist/vue-poll.min.js"></script>

范例(NPM) (Example (NPM))

Define vue-poll component markup inside your custom component.

在自定义组件内定义vue-poll组件标记。

For example in your my-poll.vue:

例如在您的my-poll.vue

<template>
    <div>
        <vue-poll v-bind="options" @addvote="addVote"/>
    </div>
</template>

<script> 
    
    import VuePoll from 'vue-poll'
    
    export default {        
        data() {
            return {
                options: {
                    question: 'What\'s your favourite <strong>JS</strong> framework?',
                    answers: [
                        { value: 1, text: 'Vue', votes: 53 },
                        { value: 2, text: 'React', votes: 35 },
                        { value: 3, text: 'Angular', votes: 30 },
                        { value: 4, text: 'Other', votes: 10 } 
                    ]
                }
            }
        },
        components: {
            VuePoll
        },
        methods: {
            addVote(obj){
                console.log('You voted ' + obj.value + '!');
            }
        }
    }
</script>

范例(CDN) (Example (CDN))

<body>
    <div id="app">
        <vue-poll v-bind="options" @addvote="addVote"/>
    </div>

    <script src="https://unpkg.com/vue-poll/dist/vue-poll.min.js"></script>
    <script> 

        Vue.use(VuePoll);

        new Vue({
            el: '#app'
            data: function() {
                return {
                    options: {
                        question: 'What\'s your favourite <strong>JS</strong> framework?',
                        answers: [
                            { value: 1, text: 'Vue', votes: 53 },
                            { value: 2, text: 'React', votes: 35 },
                            { value: 3, text: 'Angular', votes: 30 },
                            { value: 4, text: 'Other', votes: 10 } 
                        ]
                    }
                }
            },
            methods: {
                addVote: function(obj){
                    console.log('You voted ' + obj.value + '!');
                }
            }
        });
    </script>
</body>

选件 (Options)

  • 问题(必填)(字符串html) (question (required) (string-html))

    The question of the poll.

    投票的问题。

  • 答案(必填)(数组) (answers (required) (array))

    An array of the answers of the poll.

    一组民意测验的答案。

    value (required) (integer) A unique value for each answer

    值(必填)(整数)每个答案的唯一值

    text (required) (string-html) Answer's text

    文字(必填)(string-html)答案的文字

    votes (required) (integer) Answer's votes

    投票(必填)(整数)答案的投票

    custom_class (optional) (string) Custom css class for the answer element

    custom_class(可选)(字符串) answer元素的定制CSS类

  • showResults(可选)(布尔值)(默认值:false) (showResults (optional) (boolean) (default: false))

    Set this to true to skip the votting and show the results of the poll

    将此设置为true可跳过投票并显示投票结果

  • finalResults(可选)(布尔值)(默认值:false) (finalResults (optional) (boolean) (default: false))

    Set this to true to skip the votting and show the results of the poll. Winner will be highlighted

    将其设置为true可跳过投票并显示投票结果。 优胜者将突出显示

翻译自: https://vuejsexamples.com/a-twitter-like-vote-component-made-with-vue-js-2/

组件用.vue还是.js

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值