Vue移动端抽奖组件,用于大转盘滚动抽奖场景,可配置奖品、图片、转盘样式等。下面编程教程网小编给大家简单介绍一下具体实现代码!
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 内容,请继续关注编程基础学习网。
沃梦达教程
本文标题为:vue年会大转盘抽奖活动代码
基础教程推荐
猜你喜欢
- uniapp如何动态显示头部title,navigationBarTitleText动 2024-12-08
- CSS3实现双圆角Tab菜单 2024-03-30
- vue项目中在方法中控制style的方式 2023-10-08
- js select支持手动输入功能实现代码 2023-07-10
- javascript删除数组中指定元素的5种方法 2024-11-22
- PC端和移动端自适应问题的快速解决方法 2024-04-01
- js实现获取鼠标当前的位置 2023-11-30
- 珠峰基于Vue/React打造企业级技术及行业解决方案 2023-10-08
- JavaScript Rxjs mergeMap 的使用场合 2024-02-07
- vue.js 编译作用域 2023-10-08