Skip to content

Repository files navigation

# install dependencies
npm install
# serve with hot reload at localhost:8081
npm run dev
# build for production with minification
npm run build

How To Use

入口文件或相应vue文件引入

import Vue from 'vue'
import Turntable from 'vue-turntable'
Vue.use(Turntable)

template写法

 <template>
<div id="app">
<div class="turntable-box">
<turntable
:prize-all-num="8"
:prize-index="turntableOption.prizeIndex"
:duration="turntableOption.duration"
:turns-number="turntableOption.turnsNumber"
:lottery-bg="turntableOption.lotteryBg"
:pointer-bg="turntableOption.pointerBg"
:pointer-x-y="turntableOption.pointerXY"
:is-start-rotate.sync="turntableOption.isStartRotate"
@lotteryClick="lotteryClick"
@turnDoneCb="turnDoneCb" />
</div>
</div>
</template>
<script>
export default {
name: 'App',
data() {
return {
turntableOption: {
pointerXY: ["50%", "33%"],
isStartRotate: 0,
prizeIndex: 0,
duration: 5000,
turnsNumber: 4,
pointerBg: "https://res.cdn.changbaimg.com/!/yunying/nationalday2020/point_btn.png",
lotteryBg: "https://res.cdn.changbaimg.com/!/yunying/nationalday2020/turntable.png"
}
}
},
mounted() {
},
methods: {
lotteryClick() {
this.turntableOption.isStartRotate = 1;
// parseInt(Math.random()*(maxNum-minNum+1)+minNum,10);
this.turntableOption.prizeIndex = parseInt(Math.random() * (8 - 1 + 1) + 1, 10);
console.log("this.prizeIndex = ", this.turntableOption.prizeIndex);
},
turnDoneCb() {
alert('恭喜获得百万现金大奖')
}
}
}
</script>
<style lang="scss" scoped>
h1 {
text-align: center;
}
.turntable-box {
width: 540px;
height: 540px;
margin: 50px auto 0;
}
</style>

参数解释

参数名默认值用途
startAngle0初始角度
prizeAllNum8转盘均分为多少份
prizeIndex必填,中奖的下标(逆时针方向)
turnsNumber4转动的圈数
duration5000转动持续的时间,ms
lotteryBg转盘背景图
pointerBg指针背景图
pointerXY["50%", "33%"]指针坐标 数组[x,y]
isStartRotate00不转,1为开始转动
lotteryClick必填,点击抽奖按钮的事件
turnDoneCb转完后的回调函数,一般是弹出中奖后的提示

样式修改请直接覆盖class

About

vue抽奖大转盘

Resources

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages