安装
npm i vue-luck-draw
Demo演示
https://100px.net/vue-luck-draw/
使用
先找到main.js
引入插件并use
import LuckDraw from 'vue-luck-draw'
Vue.use(LuckDraw)
然后就可以使用插件了, 以下是最基本的使用
<template>
<div id="app">
<LuckDraw
ref="luckDraw"
v-model="currIndex"
:awards="awards"
:async="true"
@before-start="handleBeforeStart"
@start="handleStart"
@end="handleEnd"
/>
</div>
</template>
<script>
export default {
data () {
return {
currIndex: 0,
awards: [
{ name: '价值5988元华为 P30pro', color: '#f9e3bb' },
{ name: '价值398元车载空气净化器', color: '#f8d384' },
{ name: '价值25元百叶帘遮阳挡', color: '#f9e3bb' },
{ name: '16元油卡套餐红包', color: '#f8d384' },
{ name: '5元油卡直冲红包', color: '#f9e3bb' },
{ name: '3元话费直冲红包', color: '#f8d384' },
{ name: '价值32元重力感应手机支架', color: '#f9e3bb' },
{ name: '价值198元手提迷你车在保温冷藏箱', color: '#f8d384' },
],
}
},
methods: {
handleBeforeStart () {
setTimeout(() => {
this.$refs.luckDraw.play(3)
}, 3000)
},
handleStart () {
console.log('开始抽奖')
},
handleEnd (index) {
alert('恭喜您抽到大奖, 奖品为' + this.awards[this.currIndex].name)
}
}
}
</script>
增加异步抽奖方法:
设置属性async
=true
监听事件@before-start
,执行this.$refs.luckDraw.play(中奖的索引)
但我提供了更多可配置的参数, 比如:
<template>
<div id="app">
<LuckDraw
ref="luckDraw"
v-model="currIndex"
:awards="awards"
:rate="rate"
:radius="radius"
:textFontSize="textFontSize"
:lineHeight="lineHeight"
:textColor="textColor"
:textMargin="textMargin"
:textPadding="textPadding"
:btnFontSize="btnFontSize"
:btnColor="btnColor"
:btnBorderColor1="btnBorderColor1"
:btnBorderColor2="btnBorderColor2"
:btnBorderColor3="btnBorderColor3"
:btnBgColor="btnBgColor"
:btnText="btnText"
:btnRadius="btnRadius"
:borderColor="borderColor"
@start="handleStart"
@end="handleEnd"
/>
</div>
</template>
<script>
export default {
data () {
return {
currIndex: 0,
rate: 80,
radius: 180,
textFontSize: '13px',
lineHeight: 20,
textColor: '#d64737',
textMargin: 30,
textPadding: 0,
btnFontSize: '26px',
btnColor: '#d64737',
btnBorderColor1: '#d64737',
btnBorderColor2: '#ffffff',
btnBorderColor3: '#f6c66f',
btnBgColor: '#ffdea0',
btnText: '抽奖',
btnRadius: 60,
borderColor: '#d64737',
awards: [
{ name: '价值5988元华为 P30pro', color: '#f9e3bb' },
{ name: '价值398元车载空气净化器', color: '#f8d384' },
{ name: '价值25元百叶帘遮阳挡', color: '#f9e3bb' },
{ name: '16元油卡套餐红包', color: '#f8d384' },
{ name: '5元油卡直冲红包', color: '#f9e3bb' },
{ name: '3元话费直冲红包', color: '#f8d384' },
{ name: '价值32元重力感应手机支架', color: '#f9e3bb' },
{ name: '价值198元手提迷你车在保温冷藏箱', color: '#f8d384' },
],
}
},
methods: {
handleStart () {
console.log('开始抽奖')
},
handleEnd (index) {
alert('恭喜您抽到大奖, 奖品为' + this.awards[this.currIndex].name)
}
}
}
</script>