Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

v-luck-draw

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

v-luck-draw

基于Vue的转盘抽奖组件

latest
Source
npmnpm
Version
0.1.2
Version published
Maintainers
1
Created
Source

效果图

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转盘大小Number300
prizes奖品列表,是一个数组,数组元素包含属性text:奖品名称;icon:奖品图标(可选)Array-
fontSize奖品名称字体大小Number16
iconWidthicon:奖品图标宽度Number25
borderWidth转盘外圈与内圈直接的圆环宽度Number22
dotCount转盘外圈上的圆点个数Number24
dotRadius转盘外圈上的圆点半径Number4
dotColors转盘外圈上的圆点颜色,是一个颜色字符串数组Array['#FEE200', '#FFF']
fanneColors转盘内圈奖品扇形背景颜色,是一个颜色字符串数组Array['#ffd428', '#fff68b']
btnSize“立即抽奖”按钮大小Number40

4. 事件

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

5. 方法

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

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

Keywords

vue

FAQs

Package last updated on 18 Jun 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts