插件版 文檔地址javascript
npm install vue-luck-draw
html
//main.js import LuckDraw from "vue-luck-draw"; Vue.use(LuckDraw);
<template> <LuckyWheel ref="LuckyWheel" width="300px" height="300px" :prizes="prizes" :default-style="defaultStyle" :blocks="blocks" :buttons="buttons" @start="startCallBack" @end="endCallBack" /> </template> <script> export default { data () { return { prizes: [], defaultStyle: { fontColor: '#d64737', fontSize: '14px' }, blocks: [ { padding: '13px', background: '#d64737' } ], buttons: [ { radius: '50px', background: '#d64737' }, { radius: '45px', background: '#fff' }, { radius: '41px', background: '#f6c66f', pointer: true }, { radius: '35px', background: '#ffdea0', imgs: [{ src: require('./img/button.png'), width: '65%', top: '-50%' }] } ], } }, mounted () { this.getPrizesList() }, methods: { getPrizesList () { this.prizes = [] let data = ['1元紅包', '100元紅包', '0.5元紅包', '2元紅包', '10元紅包', '50元紅包', '0.3元紅包', '5元紅包'] data.forEach((item, index) => { this.prizes.push({ title: item, background: index % 2 ? '#f9e3bb' : '#f8d384', fonts: [{ text: item, top: '10%' }], imgs:[{ src: require(`./img/${index}.png`), width: '30%', top: '35%' }], }) }) }, startCallBack () { this.$refs.LuckyWheel.play() setTimeout(() => { this.$refs.LuckyWheel.stop(Math.random() * 8 >> 0) }, 3000) }, endCallBack (prize) { alert(`恭喜你得到${prize.title}`) }, } } </script>
padding:string background:stringvue
<LuckyWheel width="200px" height="200px" :blocks="blocks" />
data () { return { blocks: [ { padding: '10px', background: '#ffc27a' }, { padding: '10px', background: '#ff4a4c' }, { padding: '0px', background: '#fff' } ] } }