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

vue頁面使用多個定時器的方法

 更新時間:2022年09月14日 11:26:42   作者:琳木兮  
這篇文章主要為大家詳細介紹了vue頁面使用多個定時器的方法,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了vue頁面使用多個定時器的具體代碼,供大家參考,具體內(nèi)容如下

問題描述

vue頁面使用多個定時器

html:

<div class="prod-item">
? ? ? <ul>
? ? ? ? <li
? ? ? ? ? v-for="(item, index) in state.list"
? ? ? ? ? :key="index"
? ? ? ? ? :class="[
? ? ? ? ? ? item.isDisabled ? 'active_li_02' : 'active_li_01',
? ? ? ? ? ? 'flex ml-10 mr-10 ?mt-25',
? ? ? ? ? ]"
? ? ? ? >
? ? ? ? ? <div class="img">
? ? ? ? ? ? <img :src="item.imageUrl" alt="" />
? ? ? ? ? </div>
? ? ? ? ? <div class="item-right">
? ? ? ? ? ? <div
? ? ? ? ? ? ? :class="[
? ? ? ? ? ? ? ? item.isDisabled ? 'active_title_02' : 'active_title_01',
? ? ? ? ? ? ? ? 'title',
? ? ? ? ? ? ? ]"
? ? ? ? ? ? >
? ? ? ? ? ? ? {{ item.name }}
? ? ? ? ? ? </div>
? ? ? ? ? ? <van-button
? ? ? ? ? ? ? type="default"
? ? ? ? ? ? ? :class="[
? ? ? ? ? ? ? ? item.isDisabled ? 'active_btn_02' : 'active_btn_01',
? ? ? ? ? ? ? ? 'btn mt-30',
? ? ? ? ? ? ? ]"
? ? ? ? ? ? ? @click.stop="checkLoginUser(item)"
? ? ? ? ? ? ? :disabled="item.isDisabled"
? ? ? ? ? ? >
? ? ? ? ? ? ? {{ item.saleTit }}
? ? ? ? ? ? </van-button>
? ? ? ? ? </div>
? ? ? ? </li>
? ? ? </ul>
</div>

js:

js:請求數(shù)據(jù),遍歷數(shù)組,然后根據(jù)數(shù)據(jù)字段判斷,如果服務(wù)器的開始時間小于服務(wù)器的系統(tǒng)時間那就倒計時,appointmentStatus 這個字段為2的時候 且服務(wù)器的開始時間小于服務(wù)器的系統(tǒng)時間.
let appointStart = new Date( item.appointStart.replace(/-/g, "/") ).getTime(); 這個是兼容ios的時間格式

const getProdList = async () => {
? ? ? //預(yù)售商品列表
? ? ? await $api.fns.PreSale.getPreSaleList({
? ? ? ? params: {
? ? ? ? ? iconType: 2,
? ? ? ? },
? ? ? })
? ? ? ? .then((res) => {
? ? ? ? ? if (res?.data) {
? ? ? ? ? ? console.log(res.data);
? ? ? ? ? ? // `appointment_status`'預(yù)約狀態(tài) 1已上架、2已下架',
? ? ? ? ? ? state.list = res.data;
? ? ? ? ? ? res.data.map((item) => {
? ? ? ? ? ? ? item.isDisabled = true;
? ? ? ? ? ? ? item.saleTit = "等待預(yù)約";
? ? ? ? ? ? ? item.timer = null;
? ? ? ? ? ? ? if (item.appointStart) {
? ? ? ? ? ? ? ? let appointStart = new Date(
? ? ? ? ? ? ? ? ? item.appointStart.replace(/-/g, "/")
? ? ? ? ? ? ? ? ).getTime();
? ? ? ? ? ? ? ? let systemDate = new Date(
? ? ? ? ? ? ? ? ? item.systemDate.replace(/-/g, "/")
? ? ? ? ? ? ? ? ).getTime();
? ? ? ? ? ? ? ? item.times = Math.round(
? ? ? ? ? ? ? ? ? parseInt(appointStart - systemDate) / 1000
? ? ? ? ? ? ? ? );
? ? ? ? ? ? ? }
? ? ? ? ? ? });
? ? ? ? ? ? state.list = res.data;
? ? ? ? ? ? state.list.map((item, index) => {
? ? ? ? ? ? ? if (item.appointmentStatus === 2) {
? ? ? ? ? ? ? ? if (item.times) {
? ? ? ? ? ? ? ? ? // 還沒有開始預(yù)購
? ? ? ? ? ? ? ? ? if (item.times > 0) {
? ? ? ? ? ? ? ? ? ? startCountdown(item.times, index);
? ? ? ? ? ? ? ? ? ? // 預(yù)購結(jié)束
? ? ? ? ? ? ? ? ? } else {
? ? ? ? ? ? ? ? ? ? item.isDisabled = true;
? ? ? ? ? ? ? ? ? ? item.saleTit = "預(yù)購結(jié)束";
? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? // 時間為空的時候,就只有預(yù)購結(jié)束,和立即預(yù)購兩種狀態(tài)
? ? ? ? ? ? ? ? } else {
? ? ? ? ? ? ? ? ? item.isDisabled = true;
? ? ? ? ? ? ? ? ? item.saleTit = "預(yù)購結(jié)束";
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? } else {
? ? ? ? ? ? ? ? item.isDisabled = false;
? ? ? ? ? ? ? ? item.saleTit = "立即預(yù)購";
? ? ? ? ? ? ? }
? ? ? ? ? ? });
? ? ? ? ? ?
? ? ? ? ? }
? ? ? ? })
? ? ? ? .catch((error) => {
? ? ? ? ? console.log(error);
? ? ? ? });
? ? };

因為每一個定時器的時間都不一樣,所以每一個定時器結(jié)束了要清除定時器 window.clearInterval(state.list[index].timer);

// 倒計時
const startCountdown = (times, index) => {
? ? ? console.log("index", index, state.list);
? ? ? // 跟開始時間相比如果當(dāng)前時間小于開始時間,那就還沒有開始
? ? ? // let times = Math.round(parseInt(appointStart - systemDate) / 1000);
? ? ? if (times > 0) {
? ? ? ? state.list[index].timer = setInterval(() => {
? ? ? ? ? state.list[index].times--;
? ? ? ? ? console.log("state.times-----111", state.list[index].times);
? ? ? ? ? if (state.list[index].times === 0) {
? ? ? ? ? ? state.list[index].times = 0;
? ? ? ? ? ? state.list.map(() => {
? ? ? ? ? ? ? state.list[index].isDisabled = false;
? ? ? ? ? ? ? state.list[index].saleTit = "立即預(yù)購";
? ? ? ? ? ? });

? ? ? ? ? ? window.clearInterval(state.list[index].timer);
? ? ? ? ? }
? ? ? ? }, 1000);
? ? ? }
? ? };

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • 詳解webpack編譯多頁面vue項目的配置問題

    詳解webpack編譯多頁面vue項目的配置問題

    本篇文章主要介紹了詳解webpack編譯多頁面vue項目的配置問題,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-12-12
  • 如何手動銷毀Vue中掛載的組件

    如何手動銷毀Vue中掛載的組件

    這篇文章主要介紹了如何手動銷毀Vue中掛載的組件,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-08-08
  • Vue.js+express利用切片實現(xiàn)大文件斷點續(xù)傳

    Vue.js+express利用切片實現(xiàn)大文件斷點續(xù)傳

    斷點續(xù)傳就是要從文件已經(jīng)下載的地方開始繼續(xù)下載,本文主要介紹了Vue.js+express利用切片實現(xiàn)大文件斷點續(xù)傳,具有一定的參考價值,感興趣的可以了解下
    2023-05-05
  • Vue官網(wǎng)todoMVC示例代碼

    Vue官網(wǎng)todoMVC示例代碼

    本篇文章主要介紹了Vue官網(wǎng)todoMVC示例代碼,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-01-01
  • elementui中樹形表格切換展開不同層級的示例代碼

    elementui中樹形表格切換展開不同層級的示例代碼

    這篇文章主要介紹了elementui中樹形表格切換展開不同層級,本文通過示例代碼給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-08-08
  • element-plus按需引入后ElMessage與ElLoading在頁面中的使用

    element-plus按需引入后ElMessage與ElLoading在頁面中的使用

    這篇文章主要介紹了element-plus按需引入后ElMessage與ElLoading在頁面中的使用方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-09-09
  • vue使用axios獲取不到響應(yīng)頭Content-Disposition的問題及解決

    vue使用axios獲取不到響應(yīng)頭Content-Disposition的問題及解決

    這篇文章主要介紹了vue使用axios獲取不到響應(yīng)頭Content-Disposition的問題及解決,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-06-06
  • 詳解vue 組件

    詳解vue 組件

    這篇文章主要介紹了詳解vue 組件的相關(guān)知識,文中講解非常細致,代碼供大家參考學(xué)習(xí),感興趣的朋友可以了解下
    2020-06-06
  • vue后臺項目如何使用router.addRoutes動態(tài)加入路由的思路

    vue后臺項目如何使用router.addRoutes動態(tài)加入路由的思路

    這篇文章主要介紹了vue后臺項目如何使用router.addRoutes動態(tài)加入路由的思路,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2023-06-06
  • 詳解Vue 單文件組件的三種寫法

    詳解Vue 單文件組件的三種寫法

    這篇文章主要介紹了詳解Vue 單文件組件的三種寫法,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-02-02

最新評論

眉山市| 和林格尔县| 盱眙县| 襄汾县| 青神县| 调兵山市| 西林县| 宜君县| 抚远县| 阿合奇县| 巨野县| 祁东县| 宜川县| 右玉县| 陵水| 酒泉市| 泽库县| 禄丰县| 东阿县| 庄河市| 麻江县| 延长县| 河南省| 福州市| 荆门市| 玉林市| 通城县| 融水| 望城县| 富阳市| 临城县| 灯塔市| 双流县| 柳河县| 临江市| 福贡县| 广水市| 石屏县| 岑溪市| 固镇县| 贵溪市|