npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

v-luck-draw

v0.1.2

Published

基于Vue的转盘抽奖组件

Downloads

8

Readme

效果图

Demo

Demo

说明:这是基于vue开发的转盘抽奖组件。

1. 安装&使用

  • 安装
npm install v-luck-draw
  • 使用
//方法1
import LuckDraw from 'v-luck-draw'
Vue.use(LuckDraw);

//方法2
import { LuckDraw } from 'v-luck-draw'
Vue.component("LuckDraw", LuckDraw);

//方法3 假设是test.vue文件 <script>标签内使用局部注册LuckDraw组件
import { LuckDraw } from 'v-luck-draw'
export default {
    components: {
        LuckDraw
    }
}

2. 例子

  • 代码
<template>
    <div class="demo">
        <luck-draw ref="luckDraw" :prizes="prizes" @start="onStart" @finish="onFinish" />
        <div style="padding:10px;">抽中奖品:{{ prize&&prize.text||"尚未抽奖" }}</div>
        <button @click="onStopClick">停止抽奖</button>
    </div>
</template>

<script>
export default {
    data() {
        return {
            prize: null,
            prizes: [
                {
                    text: '100元', // 奖品名称
                    icon: '/img/icon.png', // 图标,如果没有则不显示
                },
                { text: '10元', icon: '/img/icon.png' },
                { text: '1000元', icon: '/img/icon.png' },
                { text: '2元', icon: '/img/icon.png' },
                { text: '1元', icon: '/img/icon.png' },
                { text: '0.5元', icon: '/img/icon.png' },
                { text: '0.5元', icon: '/img/icon.png' },
                { text: '0.5元', icon: '/img/icon.png' },
            ],
        };
    },
    methods: {
        // 点击了开始抽奖
        onStart() {
            // 模拟200ms后请求到中奖奖品
            setTimeout(() => {
            // 调用check方法,选中一个奖品索引
                this.$refs.luckDraw.check(2);
            }, 200);
        },
        // 抽中奖品,并且停止转盘后调用
        onFinish(index) {
            this.prize = this.prizes[index];
        },
        onStopClick() {
            // 主动调用stop方法停止转盘转动,在请求中奖奖品的接口出异常时调用
            this.$refs.luckDraw.stop();
        },
    },
};
</script>

3. props

|属性|说明|类型|默认值| |:-|:-|:-|:-| |size|转盘大小|Number|300| |prizes|奖品列表,是一个数组,数组元素包含属性text:奖品名称;icon:奖品图标(可选)|Array|-| |fontSize|奖品名称字体大小|Number|16| |iconWidth|icon:奖品图标宽度|Number|25| |borderWidth|转盘外圈与内圈直接的圆环宽度|Number|22| |dotCount|转盘外圈上的圆点个数|Number|24| |dotRadius|转盘外圈上的圆点半径|Number|4| |dotColors|转盘外圈上的圆点颜色,是一个颜色字符串数组|Array|['#FEE200', '#FFF']| |fanneColors|转盘内圈奖品扇形背景颜色,是一个颜色字符串数组|Array|['#ffd428', '#fff68b']| |btnSize|“立即抽奖”按钮大小|Number|40|

4. 事件

|事件名称|参数|说明| |:-|:-|:-| |start|-|点击“立即抽奖”按钮时触发| |finish|index|抽中奖品,并停止转盘转动时触发,会回调一个index参数,该参数表示抽中的奖品索引|

5. 方法

提示:给luck-draw组件增加ref属性可获取组件的Vue实例,拿到实例后可执行下面的方法。例如:

<luck-draw ref="luckDraw" />
export default {
    mounted() {
        let luckDraw = this.$refs.luckDraw;
        // 当用户点击“立即抽奖”按钮时,若请求“抽中奖品的索引”的接口出现异常时,可以调用stop方法停止转盘转动
        luckDraw.stop();
    }
}

|方法名|说明| |:-|:-| |stop|执行此方法,可以停止转盘转动。|