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

vue頁面使用多個(gè)定時(shí)器的方法

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

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

問題描述

vue頁面使用多個(gè)定時(shí)器

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

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é)束";
? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? // 時(shí)間為空的時(shí)候,就只有預(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);
? ? ? ? });
? ? };

因?yàn)槊恳粋€(gè)定時(shí)器的時(shí)間都不一樣,所以每一個(gè)定時(shí)器結(jié)束了要清除定時(shí)器 window.clearInterval(state.list[index].timer);

// 倒計(jì)時(shí)
const startCountdown = (times, index) => {
? ? ? console.log("index", index, state.list);
? ? ? // 跟開始時(shí)間相比如果當(dāng)前時(shí)間小于開始時(shí)間,那就還沒有開始
? ? ? // 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)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • 詳解webpack編譯多頁面vue項(xiàng)目的配置問題

    詳解webpack編譯多頁面vue項(xiàng)目的配置問題

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

    如何手動(dòng)銷毀Vue中掛載的組件

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

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

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

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

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

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

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

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

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

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

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

    詳解vue 組件

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

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

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

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

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

最新評(píng)論

安国市| 株洲县| 共和县| 巢湖市| 辉县市| 洞头县| 尉犁县| 烟台市| 富顺县| 合肥市| 高雄县| 江北区| 福州市| 秦皇岛市| 杭州市| 年辖:市辖区| 安义县| 台中县| 枝江市| 青阳县| 广州市| 横山县| 宁明县| 湟源县| 永年县| 惠东县| 沙洋县| 廉江市| 云龙县| 宿州市| 沙田区| 朝阳区| 石棉县| 江门市| 江孜县| 锦州市| 定州市| 师宗县| 康定县| 镇赉县| 大方县|