轮播添加节流处理, 避免一秒内多次操作

v1.0.0
于肖磊 2024-09-05 18:12:32 +08:00
parent d5af5ebbeb
commit 7df517fab7
5 changed files with 25 additions and 10 deletions

View File

@ -48,7 +48,7 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { common_styles_computer, radius_computer, get_math } from '@/utils'; import { common_styles_computer, radius_computer, get_math } from '@/utils';
import { isEmpty, cloneDeep } from 'lodash'; import { isEmpty, cloneDeep, throttle } from 'lodash';
import { Swiper, SwiperSlide } from 'swiper/vue'; import { Swiper, SwiperSlide } from 'swiper/vue';
import { Autoplay, EffectCoverflow } from 'swiper/modules'; import { Autoplay, EffectCoverflow } from 'swiper/modules';
import 'swiper/css'; import 'swiper/css';
@ -164,7 +164,10 @@ watchEffect(() => {
length: carousel_length length: carousel_length
}; };
// key // key
carouselKey.value = get_math(); // ,
throttle(() => {
carouselKey.value = get_math();
}, 1000);
} }
//#endregion //#endregion
}); });

View File

@ -149,7 +149,7 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { common_styles_computer, get_math, gradient_handle, padding_computer, radius_computer } from '@/utils'; import { common_styles_computer, get_math, gradient_handle, padding_computer, radius_computer } from '@/utils';
import { isEmpty, cloneDeep } from 'lodash'; import { isEmpty, cloneDeep, throttle } from 'lodash';
import ShopAPI from '@/api/shop'; import ShopAPI from '@/api/shop';
const props = defineProps({ const props = defineProps({
@ -449,7 +449,10 @@ watchEffect(() => {
notice_length: notice_length, notice_length: notice_length,
}; };
// key // key
carouselKey.value = get_math(); // ,
throttle(() => {
carouselKey.value = get_math();
}, 1000);
} }
}); });
//#endregion //#endregion

View File

@ -26,7 +26,7 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { common_styles_computer, radius_computer, get_math } from '@/utils'; import { common_styles_computer, radius_computer, get_math } from '@/utils';
import { isEmpty, cloneDeep } from 'lodash'; import { isEmpty, cloneDeep, throttle } from 'lodash';
const props = defineProps({ const props = defineProps({
value: { value: {
@ -141,7 +141,10 @@ watch(props.value, (val) => {
is_roll: display_is_roll, is_roll: display_is_roll,
}; };
// key // key
carouselKey.value = get_math(); // ,
throttle(() => {
carouselKey.value = get_math();
}, 1000);
} }
nextTick(() => { nextTick(() => {
if (!isEmpty(bannerImg.value)) { if (!isEmpty(bannerImg.value)) {

View File

@ -42,7 +42,7 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { background_computer, common_styles_computer, get_math, gradient_computer, gradient_handle, radius_computer } from '@/utils'; import { background_computer, common_styles_computer, get_math, gradient_computer, gradient_handle, radius_computer } from '@/utils';
import { isEmpty, cloneDeep } from 'lodash'; import { isEmpty, cloneDeep, throttle } from 'lodash';
const props = defineProps({ const props = defineProps({
value: { value: {
@ -134,7 +134,10 @@ watchEffect(() => {
notice_length: notice_length notice_length: notice_length
}; };
// key // key
carouselKey.value = get_math(); // ,
throttle(() => {
carouselKey.value = get_math();
}, 1000);
} }
//#endregion //#endregion
}); });

View File

@ -160,7 +160,7 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { background_computer, common_styles_computer, get_math, gradient_computer, gradient_handle, padding_computer, radius_computer } from '@/utils'; import { background_computer, common_styles_computer, get_math, gradient_computer, gradient_handle, padding_computer, radius_computer } from '@/utils';
import { isEmpty } from 'lodash'; import { isEmpty, throttle } from 'lodash';
import SeckillAPI from '@/api/seckill'; import SeckillAPI from '@/api/seckill';
import { online_url } from '@/utils'; import { online_url } from '@/utils';
import { Swiper, SwiperSlide } from 'swiper/vue'; import { Swiper, SwiperSlide } from 'swiper/vue';
@ -434,7 +434,10 @@ watchEffect(() => {
// //
slides_per_group.value = new_style.value.rolling_fashion == 'translation' ? 1 : form.value.carousel_col; slides_per_group.value = new_style.value.rolling_fashion == 'translation' ? 1 : form.value.carousel_col;
// key // key
carouselKey.value = get_math(); // ,
throttle(() => {
carouselKey.value = get_math();
}, 1000);
}); });
// //