Vue移动端抽奖组件,用于大转盘滚动抽奖场景,可配置奖品、图片、转盘样式等。下面web建站小编给大家简单介绍一下具体实现代码!
vue组件安装
import { createApp } from "vue"; // vue import { Turntable } from "@nutui/nutui-bingo"; // taro import { Turntable } from "@nutui/nutui-bingo-taro"; const app = createApp(); app.use(Turntable);
vue基础用法
<template> <nutbig-turntable class="turntable" ref="turntable" :width="luckWidth" :height="luckheight" :prize-list="prizeList" :turns-number="turnsNumber" :turns-time="turnsTime" :prize-index="prizeIndex" :style-opt="styleOpt" :pointer-style="pointerStyle" @start-turns="startTurns" @end-turns="endTurns" > </nutbig-turntable> </template> <script> import { Toast } from "@nutui/nutui"; import { ref, reactive } from "vue"; export default { setup() { const turntable = ref(null); // 转盘大小 const luckWidth = ref("450px"); const luckheight = ref("450px"); // 转盘指针图片样式 const pointerStyle = { width: "80px", height: "80px", backgroundImage:'url("背景图片")', backgroundSize: "contain", backgroundRepeat: "no-repeat", }; // 转盘上要展示的奖品数据 const prizeList = ref([ { id: "xiaomi", prizeName: "小米手机", prizeImg: "小米手机图片.jpg", }, { id: "huawei", prizeColor: "rgb(251, 219, 216)", prizeName: "华为手机", prizeImg: "华为手机图片.jpg", }, { id: "apple", prizeName: "apple watch", prizeImg: "apple watch.jpg", }, { id: "shubiao", prizeColor: "rgba(246, 142, 46, 0.5)", prizeName: "鼠标", prizeImg: "鼠标.jpg", }, { id: "jianpan", prizeName: "键盘.jpg", prizeImg: "", }, { id: "thanks", prizeName: "谢谢参与", prizeImg: "谢谢参与.jpg", }, ]); // 转动圈数 const turnsNumber = ref(5); // 转动需要持续的时间(秒) const turnsTime = ref(5); // 转盘样式的选项 const styleOpt = reactive({ // 转盘中每一块扇形的背景色,根据奖品的index来取每一块的对应颜色 prizeBgColors: [ "rgb(255, 231, 149)", "rgb(255, 247, 223)", "rgb(255, 231, 149)", "rgb(255, 247, 223)", "rgb(255, 231, 149)", "rgb(255, 247, 223)", ], // 每一个扇形的外边框颜色 borderColor: "#ff9800", }); // 中奖的奖品的index(此数据可根据后台返回的值重新赋值) const prizeIndex = ref(-1); // 剩余抽奖次数 const num = ref(5); const startTurns = () => { const index = Math.floor(Math.random() * prizeList.value.length); prizeIndex.value = index; turntable.value.rotateTurn(); }; const endTurns = () => { console.log("中奖了"); }; return { turntable, luckWidth, luckheight, pointerStyle, prizeList, turnsNumber, turnsTime, styleOpt, prizeIndex, num, startTurns, endTurns, }; }, }; </script>
上面是“vue年会大转盘抽奖活动代码”的全面内容,想了解更多关于 vuejs 内容,请继续关注web建站教程。
当前网址:https://ipkd.cn/webs_14315.html
workflows工作流
- 去掉背景(抠图)comfyui工作流
- 羚羊安上小白兔的门牙ComfyUI工作流
- 蘑菇屋,梦幻家园comfyui工作流
- 一只可爱的毛茸茸的猫ComfyUI工作流
- 一个漂亮的混血女孩ComfyUI工作流
- 一辆在泥潭中奔跑的布加迪ComfyUI工作流
- 一只可爱的快乐老鼠戴着帽子ComfyUI工作流
- 乒乓卡通3d人物
猜你喜欢
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!