vue3實(shí)現(xiàn)抽獎(jiǎng)模板設(shè)置
本文實(shí)例為大家分享了vue3實(shí)現(xiàn)抽獎(jiǎng)模板設(shè)置的具體方法,供大家參考,具體內(nèi)容如下
效果圖
代碼
<template> ? <div> ? ? <h4>抽獎(jiǎng)模板設(shè)置</h4> ? ? <div class="container"> ? ? ? <ul class="ul-box"> ? ? ? ? <li ? ? ? ? ? v-for="(item,index) in list" ? ? ? ? ? :key="item.id" ? ? ? ? ? @click.stop="handleClickItem(item,index)" ? ? ? ? > ? ? ? ? ? {{item.id}}-{{item.title}} ? ? ? ? </li> ? ? ? </ul> ? ? ? <div ? ? ? ? class="pop-box" ? ? ? ? v-show="visible" ? ? ? > ? ? ? ? <div ? ? ? ? ? class="popup" ? ? ? ? ? :style="{left:clickIndexList[0]+'px',top:clickIndexList[1]+'px'}" ? ? ? ? > ? ? ? ? ? <span><em></em></span> ? ? ? ? ? <div> ? ? ? ? ? ? <p ? ? ? ? ? ? ? class="p-title" ? ? ? ? ? ? ? v-for="(item) in selectList" ? ? ? ? ? ? ? :key="item.id" ? ? ? ? ? ? ? @click.stop="handleChoose(item)" ? ? ? ? ? ? >{{item.title}}</p> ? ? ? ? ? </div> ? ? ? ? </div> ? ? ? </div> ? ? </div> ? </div> </template> <script lang="ts"> import { defineComponent, reactive, toRefs, onMounted } from 'vue'; const WIDTH = 100; export default defineComponent({ ? name: 'test', ? components: {}, ? setup() { ? ? const state = reactive({ ? ? ? list: [ ? ? ? ? { id: 1 }, ? ? ? ? { id: 2 }, ? ? ? ? { id: 3 }, ? ? ? ? { id: 4 }, ? ? ? ? { id: 5, title: '抽獎(jiǎng)' }, ? ? ? ? { id: 6 }, ? ? ? ? { id: 7 }, ? ? ? ? { id: 8 }, ? ? ? ? { id: 9 }, ? ? ? ], ? ? ? selectList: [ ? ? ? ? { id: 1, title: '謝謝參與' }, ? ? ? ? { id: 2, title: 'iphone13' }, ? ? ? ? { id: 3, title: '領(lǐng)克06' }, ? ? ? ? { id: 4, title: '華為p40' }, ? ? ? ], ? ? ? visible: false, ? ? ? clickIndexList: [], ? ? ? clickIndex: 0, ? ? }); ? ? const xyList = [ ? ? ? [0, 0], ? ? ? [WIDTH, 0], ? ? ? [WIDTH * 2, 0], ? ? ? [0, WIDTH], ? ? ? [WIDTH, WIDTH], ? ? ? [WIDTH * 2, WIDTH], ? ? ? [0, WIDTH * 2], ? ? ? [WIDTH, WIDTH * 2], ? ? ? [WIDTH * 2, WIDTH * 2], ? ? ]; ? ? const hide = () => { ? ? ? state.visible = false; ? ? }; ? ? onMounted(() => { ? ? ? document.addEventListener('click', hide); ? ? }); ? ? const handleClickItem = (item, index) => { ? ? ? if (index === 4) { ? ? ? ? return; ? ? ? } ? ? ? state.clickIndexList = xyList[index]; ? ? ? state.clickIndex = index; ? ? ? state.visible = true; ? ? }; ? ? const handleChoose = (item) => { ? ? ? state.list[state.clickIndex].title = item.title; ? ? ? hide(); ? ? }; ? ? return { ? ? ? handleClickItem, ? ? ? hide, ? ? ? handleChoose, ? ? ? ...toRefs(state), ? ? }; ? }, }); </script> <style lang="less" scoped> .container { ? position: relative; ? .ul-box { ? ? display: flex; ? ? flex-wrap: wrap; ? ? width: 300px; ? ? li { ? ? ? width: 100px; ? ? ? height: 100px; ? ? ? background: pink; ? ? ? border: 1px solid #fff; ? ? ? display: flex; ? ? ? justify-content: center; ? ? ? align-items: center; ? ? ? cursor: pointer; ? ? } ? } ? .p-title { ? ? margin: 0; ? ? min-width: 150px; ? ? font-size: 14px; ? ? line-height: 1.4; ? ? padding: 10px 20px; ? ? cursor: pointer; ? } ? .p-title:hover { ? ? background: #e6ebf5; ? } ? .pop-box .popup { ? ? width: 200px; ? ? background: #fff; ? ? color: #333; ? ? border-radius: 4px; ? ? position: absolute; ? ? top: 30px; ? ? left: 30px; ? ? border: 1px solid #e6ebf5; ? ? margin-left: -50px; ? ? margin-top: 60px; ? ? z-index: 9999; ? ? animation: left 1s; ? } ? .pop-box .popup span { ? ? display: block; ? ? width: 0; ? ? height: 0; ? ? border-width: 0 10px 10px; ? ? border-style: solid; ? ? border-color: transparent transparent #e6ebf5; ? ? position: absolute; ? ? top: -10px; ? ? left: 50%; /* 三角形居中顯示 */ ? ? margin-left: -10px; /* 三角形居中顯示 */ ? } ? .pop-box .popup em { ? ? display: block; ? ? width: 0; ? ? height: 0; ? ? border-width: 0 10px 10px; ? ? border-style: solid; ? ? border-color: transparent transparent #fff; ? ? position: absolute; ? ? top: 1px; ? ? left: -10px; ? } } </style>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
vant開發(fā)微信小程序安裝以及簡(jiǎn)單使用教程
這篇文章主要介紹了vant開發(fā)微信小程序安裝以及簡(jiǎn)單使用教程,需要的朋友可以參考下2022-12-12Vue子組件props從父組件接收數(shù)據(jù)并存入data
這篇文章主要介紹了Vue子組件props從父組件接收數(shù)據(jù)并存入data的方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2022-08-08element-ui 表格數(shù)據(jù)時(shí)間格式化的方法
這篇文章主要介紹了element-ui 表格數(shù)據(jù)時(shí)間格式化的方法,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-08-08vue面試??贾甤omputed是如何實(shí)現(xiàn)的
對(duì)于每天都在用的計(jì)算屬性(computed),小編猜大家肯定也想窺探其奧妙與原理對(duì)吧,所以這篇文章就來(lái)講講computed是如何實(shí)現(xiàn)的吧,感興趣的小伙伴可以學(xué)習(xí)一下2023-08-08使用Element進(jìn)行前端開發(fā)的詳細(xì)圖文教程
眾所周知Element是一套Vue.js后臺(tái)組件庫(kù),它能夠幫助你更輕松更快速地開發(fā)后臺(tái)項(xiàng)目,下面這篇文章主要給大家介紹了關(guān)于使用Element進(jìn)行前端開發(fā)的相關(guān)資料,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-11-11vue項(xiàng)目打包后放服務(wù)器非根目錄下圖片找不到問(wèn)題
這篇文章主要介紹了vue項(xiàng)目打包后放服務(wù)器非根目錄下圖片找不到問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-12-12vue3+element Plus實(shí)現(xiàn)在table中增加一條表單數(shù)據(jù)的示例代碼
這篇文章主要介紹了vue3+element Plus實(shí)現(xiàn)在table中增加一條表單數(shù)據(jù)的操作,本文通過(guò)示例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧2024-01-01