[英]why onclick function is not working in my Vue app?
please help me solve the following.请帮我解决以下问题。 I am trying to add onclick event to my slider, and while am using Vue 3, the esling gives me 'is assigned a value but never used, no-unused-vars' error.
我正在尝试将 onclick 事件添加到我的 slider,并且在使用 Vue 3 时,esling 给我“已分配一个值但从未使用过,没有未使用的变量”错误。 the below is my code, could someone please help.
以下是我的代码,有人可以帮忙吗。
<template>
<div class="carousel">
<slot :currentSlide="currentSlide" />
<!-- Navigation -->
<div class="navigation">
<div class="toggle-page left">
<i @click="prevSlide" class="bi bi-arrow-left-short"></i>
</div>
<div class="toggle-page right">
<i @click="nextSlide" class="bi bi-arrow-right-short"></i>
</div>
</div>
</div>
</template>
<script>
import { ref, onMounted } from "vue";
export default {
setup() {
const currentSlide = ref(1);
const getSlideCount = ref(null);
// next slide
const nextSlide = () => {
if (currentSlide.value === getSlideCount.value) {
currentSlide.value = 1;
return;
}
currentSlide.value += 1;
};
// prev slide
const prevSlide = () =>{
if(currentSlide.value === 1){
currentSlide.value = 1;
return;
}
currentSlide.value -= 1;
}
onMounted(() => {
getSlideCount.value = document.querySelectorAll('.slide').length;
})
return { currentSlide };
},
};
</script>
You need to return your function from setup also:您还需要从设置中返回您的 function:
return { currentSlide, prevSlide, nextSlide };
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.