Vue移动端抽奖组件,用于商城摇一摇抽奖活动,可配置图片、摇晃设备回调等。下面编程教程网小编给大家简单介绍一下具体实现代码!
vue组件安装
import { createApp } from "vue";
// vue
import { Luckshake } from "@nutui/nutui-bingo";
// taro
import { Luckshake } from "@nutui/nutui-bingo-taro";
const app = createApp();
app.use(Luckshake);
vue基础用法
<template>
<div
class="demo1"
style="background: url('背景图片.png') no-repeat top center/100% 100%"
>
<nutbig-luckshake
ref="luckshakePrize"
:luck-width="luckWidth"
:luck-height="luckheight"
@shake-event="shakeEvent()"
@click-shake="handelClick()"
>
</nutbig-luckshake>
</div>
</template>
<script>
import { ref, onMounted } from "vue";
export default {
setup() {
// 红包大小
const luckWidth = ref("200px");
const luckheight = ref("160px");
// 剩余抽奖次数
let shakeNum = ref(3);
const shakeEvent = () => {
if (shakeNum.value == 0) {
console.log(`无抽奖次数`);
} else if (shakeNum.value == 1) {
setTimeout(() => {
console.log(`中奖啦`);
}, 200);
shakeNum.value -= 1;
} else {
setTimeout(() => {
console.log(`抽奖次数还剩${shakeNum.value}次`); // Do something
}, 200);
shakeNum.value -= 1;
}
};
const handelClick = () => {
console.log("点击摇一摇");
if (shakeNum.value == 0) {
console.log(`无抽奖次数`);
} else if (shakeNum.value == 1) {
setTimeout(() => {
console.log(`中奖啦`);
}, 200);
shakeNum.value -= 1;
} else {
setTimeout(() => {
console.log(`抽奖次数还剩${shakeNum.value}次`); // Do something
}, 200);
shakeNum.value -= 1;
}
};
return {
luckWidth,
luckheight,
shakeNum,
shakeEvent,
handelClick,
};
},
};
</script>
以上是编程学习网小编为您介绍的“vue红包摇一摇抽奖活动代码”的全面内容,想了解更多关于 vuejs 内容,请继续关注编程基础学习网。
沃梦达教程
本文标题为:vue红包摇一摇抽奖活动代码
基础教程推荐
猜你喜欢
- 详解H5本地储存Web Storage 2024-04-08
- JavaScript获取用户所在城市及地理位置 2024-01-05
- 如何使用html5与css3完成google涂鸦动画 2024-04-03
- TRON波场DAPP对接(tronWeb+vue) 2023-10-08
- AngularJS学习笔记之表单验证功能实例详解 2024-04-08
- vue3:vue2中protoType更改为config.globalProperties问题 2024-04-23
- 微信小程序路由跳转两种方式示例解析 2024-02-07
- 3.实体标签.html 2023-10-28
- js轮盘抽奖实例分析 2024-04-01
- js清理Word格式示例代码 2023-12-01