最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Vue.js實現(xiàn)大轉(zhuǎn)盤抽獎總結(jié)及實現(xiàn)思路

 更新時間:2019年10月09日 09:10:32   作者:碼上組合  
這篇文章主要介紹了 Vue.js實現(xiàn)大轉(zhuǎn)盤抽獎總結(jié)及實現(xiàn)思路,本文通過實例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價值,需要的朋友可以參考下

 大家好!先上圖看看本次案例的整體效果。

       實現(xiàn)思路:

Vue component實現(xiàn)大轉(zhuǎn)盤組件,可以嵌套到任意要使用的頁面。

css3 transform控制大轉(zhuǎn)盤抽獎過程的動畫效果。

抽獎組件內(nèi)使用鉤子函數(shù)watch監(jiān)聽抽獎結(jié)果的返回情況播放大轉(zhuǎn)盤動畫并給用戶彈出中獎提示。

中獎結(jié)果彈窗,為抽獎組件服務(wù)。

       實現(xiàn)步驟如下:

 構(gòu)建api獎品配置信息和抽獎接口,vuex全局存放獎品配置和中獎結(jié)果數(shù)據(jù)信息。

api:

export default {
 getPrizeList () {
  let prizeList = [
   {
    id: 1,
    name: '小米8',
    img: 'https://i1.mifile.cn/f/i/g/2015/cn-index/m8-140.png'
   },
   {
    id: 2,
    name: '小米電視',
    img: 'https://i1.mifile.cn/f/i/g/2015/TV4A-43QC.png'
   }, {
    id: 3,
    name: '小米平衡車',
    img: 'https://i1.mifile.cn/f/i/g/2015/cn-index/scooter-140!140x140.jpg'
   }, {
    id: 4,
    name: '小米耳機(jī)',
    img: 'https://c1.mifile.cn/f/i/g/2015/video/pinpai140!140x140.jpg'
   }
  ]
  return prizeList
 },
 lottery () {
  return {
   id: 4,
   name: '小米耳機(jī)',
   img: 'https://c1.mifile.cn/f/i/g/2015/video/pinpai140!140x140.jpg'
  }
 }
}

store:

import lotteryApi from '../../api/lottery.api.js'
const state = {
 prizeList: [],
 lotteryResult: {}
}
const getters = {
 prizeList: state => state.prizeList,
 lotteryResult: state => state.lotteryResult
}
const mutations = {
 SetPrizeList (state, { prizeList }) {
  state.prizeList = prizeList
 },
 SetLotteryResult (state, { lotteryResult }) {
  state.lotteryResult = lotteryResult
 }
}
const actions = {
 getPrizeList ({ commit }) {
  let result = lotteryApi.getPrizeList()
  commit('SetPrizeList', { prizeList: result })
 },
 lottery ({ commit }) {
  let result = lotteryApi.lottery()
  commit('SetLotteryResult', { lotteryResult: result })
 }
}

export default {
 state,
 getters,
 mutations,
 actions,
 namespaced: true
}

編寫抽獎組件,為保證通用性,組件只負(fù)責(zé)播放抽獎結(jié)果。接收兩個數(shù)據(jù)和一個方法,如下:

數(shù)據(jù)一:預(yù)置的獎品列表數(shù)據(jù)(輪播獎品需要)

數(shù)據(jù)二:抽獎結(jié)果,播放抽獎動畫和彈出中獎結(jié)果需要

方法:抽獎動作,返回的抽獎結(jié)果數(shù)據(jù)即為數(shù)據(jù)二,響應(yīng)式傳遞給組件

大概代碼思路如下(僅供參考,不可運行)

<template>
 <section>
  <div class="lucky-item">
   <img src="http://www.cnblogs.com/images/cnblogs_com/codeon/878827/o_backImage.jpg"
      alt>
   <div class="lucky-box">
    <img src="http://www.cnblogs.com/images/cnblogs_com/codeon/878827/o_circle.jpg"
       alt>
    <ul id="wheel"
      class="wheel-list"
      :style="wheelStyle"
      :class="transition">
     <li v-for="(prize,index) in slotPrizes"
       :style="{transform: 'rotate('+index*45+'deg)'}"
       v-bind:key="index">
      <div class="fan-item"
         style="transform: rotate(15deg) skewY(45deg);"></div>
      <div class="lucky-prize">
       <h3>{{prize.name}}</h3>
      </div>
     </li>
    </ul>
    <div class="wheel-btn"
       @click="$emit('lottery')">
     <a>
      <img src="http://images.cnblogs.com/cnblogs_com/codeon/878827/o_go.jpg"
         alt>
     </a>
    </div>
   </div>
   <prize-pop :prize="lotteryResult"
         v-if="showPrize"
         @closeLotteryPop="showPrize=false" />
  </div>
 </section>
</template>
<script>
import PrizePop from './common/prize-pop.vue'
export default {
 name: 'BigTurntable',
 data () {
  return {
   isStart: false,
   showPrize: false,
   wheelStyle: { 'transform': 'rotate(0deg)' },
   transition: 'transitionclear',
   playTurns: 5 // 默認(rèn)先旋轉(zhuǎn)5圈
  }
 },
 components: {
  PrizePop
 },
 props: {
  prizes: {
   type: Array,
   required: false
  },
  lotteryResult: {
   type: Object,
   default: () => { }
  }
 },
 computed: {
  slotPrizes () {
   var self = this
   console.log(self.prizes)
   let prizeList = []
   prizeList.push({ ...self.prizes[0], slotIndex: 1 })
   prizeList.push({ name: '謝謝參與', slotIndex: 2 })
   prizeList.push({ ...self.prizes[1], slotIndex: 3 })
   prizeList.push({ name: '謝謝參與', slotIndex: 4 })
   prizeList.push({ ...self.prizes[2], slotIndex: 5 })
   prizeList.push({ name: '謝謝參與', slotIndex: 6 })
   prizeList.push({ ...self.prizes[3], slotIndex: 7 })
   prizeList.push({ name: '謝謝參與', slotIndex: 8 })
   console.log(prizeList)
   return prizeList
  }
 },
 methods: {
  /**
   * 執(zhí)行抽獎動畫
   */
  playWheel (index) {
   
  },
   /**
   * 獲取中獎結(jié)果所在獎品列表中的索引,以確定抽獎動畫最終落在哪個獎品
  */
  getPrizeIndex (prizeId) {
  
  }
 },
 watch: {
/**
   * 監(jiān)聽抽獎結(jié)果,一旦有中獎信息就開始執(zhí)行抽獎動畫
   */
  lotteryResult (newVal, oldVal) {
   var self = this
   if (newVal.id && newVal.id > 0) {
    let index = self.getPrizeIndex(newVal.id)
    self.playWheel(index)
   }
  }
 }
}
</script>

彈出中獎結(jié)果組件,依附于抽獎組件,在上一步的執(zhí)行抽獎結(jié)果動畫結(jié)束后執(zhí)行。

<template>
<div class="subject-pop" style="z-index: 10;" v-if="prize.id>0">
   <div class="subject-pop-mask"></div>
   <div class="subject-pop-box">
    <h3>恭喜您</h3>
    <p>
     <img :src="prize.img" alt>
    </p>
    <h4>獲得
     <span></span>
     <span>{{prize.name}}</span>
    </h4>
    <div class="subject-pop-footer">
     <a href="javascript:;" rel="external nofollow" class="november-btn1" @click="closeLotteryEmit">知道了</a>
    </div>
   </div>
  </div>
</template>
<script>
export default {
 props: {
  prize: {
   type: Object,
   default: () => {
    return {
     id: 0
    }
   }
  }
 },
 methods: {
  closeLotteryEmit () {
   this.$emit('closeLotteryPop')
  }
 }
}
</script>

抽獎組件運用在需要使用的頁面中,此頁面需要為抽獎組件提前準(zhǔn)備好預(yù)置獎品列表和中獎結(jié)果信息,并提供好抽獎方法供子組件(抽獎組件)觸發(fā),觸發(fā)完更改抽獎結(jié)果響應(yīng)式傳入到抽獎組件中。

<template>
 <section>
  <div style="width:100%;text-align:center;margin:2rem 0;">您有一次抽獎機(jī)會,祝君好運~~~</div>
  <BigTurntable :prizes="prizeList"
         :lotteryResult="lotteryResult"
         @lottery="lottery" />
 </section>
</template>

<script>
import { mapGetters, mapActions } from 'vuex'
import BigTurntable from '@/components/bigTurntable.vue'
export default {
 name: 'BigTurntableRun',
 created () {
  var self = this
  self.getPrizeList()
 },
 components: {
  BigTurntable
 },
 computed: {
  ...mapGetters({
   prizeList: 'lottery/prizeList',
   lotteryResult: 'lottery/lotteryResult'
  })
 },
 methods: {
  ...mapActions({
   getPrizeList: 'lottery/getPrizeList',
   lottery: 'lottery/lottery'
  })
 }
}
</script>

總結(jié)

以上所述是小編給大家介紹的Vue.js實現(xiàn)大轉(zhuǎn)盤抽獎總結(jié)及實現(xiàn)思路,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
如果你覺得本文對你有幫助,歡迎轉(zhuǎn)載,煩請注明出處,謝謝!

相關(guān)文章

  • windows下vue-cli及webpack搭建安裝環(huán)境

    windows下vue-cli及webpack搭建安裝環(huán)境

    這篇文章主要介紹了windows下vue-cli及webpack搭建安裝環(huán)境,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-04-04
  • vue實現(xiàn)購物車完整功能

    vue實現(xiàn)購物車完整功能

    這篇文章主要為大家詳細(xì)介紹了vue實現(xiàn)購物車完整功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-01-01
  • Vue中$emit調(diào)用父組件異步方法模擬.then實現(xiàn)方式

    Vue中$emit調(diào)用父組件異步方法模擬.then實現(xiàn)方式

    這篇文章主要介紹了Vue中$emit調(diào)用父組件異步方法模擬.then實現(xiàn)方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-09-09
  • vue.js移動數(shù)組位置,同時更新視圖的方法

    vue.js移動數(shù)組位置,同時更新視圖的方法

    下面小編就為大家分享一篇vue.js移動數(shù)組位置,同時更新視圖的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-03-03
  • 解析vue.js中常用v-指令

    解析vue.js中常用v-指令

    本文以click為例給大家介紹vue.js中常用v-指令,可以用 v-on 指令監(jiān)聽 DOM 事件,并在觸發(fā)時運行一些 JavaScript代碼,本文通過示例代碼給大家介紹的非常詳細(xì),感興趣的朋友跟隨小編一起看看吧
    2021-10-10
  • VUE3中h()函數(shù)和createVNode()函數(shù)的使用解讀

    VUE3中h()函數(shù)和createVNode()函數(shù)的使用解讀

    這篇文章主要介紹了VUE3中h()函數(shù)和createVNode()函數(shù)的使用解讀,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-08-08
  • Vue3捕獲和處理不同層級的異常/錯誤的有效方法

    Vue3捕獲和處理不同層級的異常/錯誤的有效方法

    項目中如果沒有對異常做處理,可能導(dǎo)致應(yīng)用崩潰或顯示報錯信息影響用戶體驗,因此需要對不同層級的錯誤進(jìn)行捕獲,所以本文給大家介紹了Vue3捕獲和處理不同層級的異常/錯誤的有效方法,需要的朋友可以參考下
    2025-01-01
  • 如何用vue2+element-ui實現(xiàn)多行行內(nèi)表格編輯

    如何用vue2+element-ui實現(xiàn)多行行內(nèi)表格編輯

    最近開發(fā)項目,關(guān)于表格的數(shù)據(jù)操作比較多,這個地方個人覺得比較難搞,特此記錄一下,這篇文章主要給大家介紹了關(guān)于如何用vue2+element-ui實現(xiàn)多行行內(nèi)表格編輯的相關(guān)資料,需要的朋友可以參考下
    2024-08-08
  • 使用el-form之表單校驗自動定位到報錯位置問題

    使用el-form之表單校驗自動定位到報錯位置問題

    這篇文章主要介紹了使用el-form之表單校驗自動定位到報錯位置問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2023-05-05
  • Vue對象的組成和掛載方式詳解

    Vue對象的組成和掛載方式詳解

    這篇文章主要介紹了Vue對象的基本組成和Vue對象掛載的幾種方式,文中通過代碼示例給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作有一定的幫助,需要的朋友可以參考下
    2024-07-07

最新評論

莆田市| 迁安市| 康乐县| 新晃| 江永县| 保亭| 金乡县| 蓬溪县| 墨竹工卡县| 江达县| 墨江| 静海县| 屏南县| 滨州市| 雷山县| 夹江县| 乐昌市| 邵阳县| 田东县| 张掖市| 比如县| 奎屯市| 平谷区| 阿拉善盟| 武城县| 太仆寺旗| 吕梁市| 龙胜| 花垣县| 广水市| 大同县| 洪江市| 尚义县| 团风县| 棋牌| 衡水市| 宁波市| 澄迈县| 麦盖提县| 淮安市| 尉犁县|