首页 > 其他分享 >2023-07-25 uview1.0的u-number-box组件在渲染时会触发change,如何才能避免事件影响?==》设置判断条件并增加时间延迟

2023-07-25 uview1.0的u-number-box组件在渲染时会触发change,如何才能避免事件影响?==》设置判断条件并增加时间延迟

时间:2023-07-25 14:11:27浏览次数:47  
标签:box 25 触发 时间延迟 购物车 500 组件 change isDo

前言:购物车用到加减购物车数量的一个步进器组件,使用的是uview组件1.0版本的u-number-box。

该组件设置了一个@change事件,该事件会在页面渲染的时候触发一次,如果你在里面调用了接口,比如增加/减少购物车数量,那么每次一刷新购物车该事件就会被触发,从而导致不必要的报错。

解决方案:

在data定义一个变量用于判断是否执行调接口的逻辑:

isDo: true,

然后在@change对应事件中调用接口之前判断isDo为true就阻止,即:

if (this.isDo) return;

最后在mounted里面设置500毫秒延迟,500毫秒后设置isDo为false,那么在渲染的时候就不会触发@change里面的接口了,而且500毫秒后该接口就变成了允许触发。

  mounted() {
    setTimeout(() => {
      this.isDo = false;
    }, 500);
  },

 

标签:box,25,触发,时间延迟,购物车,500,组件,change,isDo
From: https://www.cnblogs.com/iuniko/p/17579749.html

相关文章

  • 2023-07-25 html中引入vue,报错:Vue is not a constructor ==》引用的vue版本不兼容导致
    报错代码:我使用的vue外链https://cdn.jsdelivr.net/npm/vue,该外链引用的是最新的[email protected]版本,而我的vue写法为vue2.0版本的写法,故而不兼容。解决方案:引用指定版本的vue......
  • 7.25打卡
    L1-093猜帽子游戏#include<bits/stdc++.h>usingnamespacestd;intmain(){intn;cin>>n;inta[n],b[n];for(inti=0;i<n;i++){cin>>a[i];}intk;cin>>k;for(inti=0;i<k;i++){intsum=0;......
  • 2023/7/25
    今天了解了两种大数类,一种是Biginteger,一种是BigDecimal。前者只能运算整数,后者可以运算小数package大数类;importjava.math.BigInteger;publicclassBigInteger类{publicstaticvoidmain(String[]args){BigIntegera1=newBigInteger("12345678987......
  • min25筛
    时间复杂度为解决的问题有:用来求积性函数前缀和,要求有是一个关于质数p的项数较小的多项式或者能快速求值可以快速求值前置知识:积性函数:对于互质的整数和有性质完全积性函数:对于任意整数和有性质规定是从小到大第零个质数,是从小到大第一个质数在以内没有任何一个合数的最小质因子......
  • antd 组件 select input cheeckboxGround 传参 自定义传参
    tempfunclog:......
  • 使用 MyBatis 相关依赖包(20230725)
    开发SpringBoot应用时使用MyBatis的相关依赖包…… 说明:本文首次发布于2023-7-2510点(北京时间),其中的“最新”是这个时间点最新。 0、序章梳理开发SpringBoot项目时,使用各种MyBatis相关依赖包的版本及其关系。 1、SpringBoot2.7.13默认MyBatisFramewo......
  • 20230725
    复赛动态规划——01背包例题:采药题目描述时间限制:1s空间限制:256M题目描述:松下问童子,言师采药去,云深不知处,只在此山中辰辰是个天资聪颖的孩子,他的梦想是成为世界上最伟大的医师。为此,他想拜附近最有威望的医师为师。医师为了判断他的资质,给他出了一个难题。医师把他带到一......
  • hackthebox pollution insane
    startofnamp  it'sbannbertellsusit'sapachealsorunningdebianandmoreimportatntlywegetaphpsessioncookieidbacksochancesarethisisgoingtobeaphpwebsitelet'sgotakealookatthepage rolltothedeepandwefind......
  • virtualbox "UEFI Interactive Shell... " 错误 virtualbox machine boots to efi she
    ItturnsoutthatasIwasmessingaroundwithgettingthemachinetoload(duetoVirtualizationtechnologiesbeingdisabled),Iclickedonetoomanyitemsontheimagesettingspage. Tofixthis,gotothe"Settings"pageforthevirtualmachi......
  • ubuntu “vt-x/amd-v hardware acceleration virtualbox" 错误
    BeforechangingBIOSsettingswemaywanttoseeifhardwarevirtualization(VT-xforIntel,AMD-VforAMDprocessors)wasalreadyenabled. Fromaterminalissuegrep--colorvmx/proc/cpuinfo##foranIntelprocessorgrep--colorsvm/proc/cpuinfo##f......