(component): 优化 carouselItem 代码 ts 警告

This commit is contained in:
就眠儀式 2022-10-15 23:05:06 +08:00
parent 617cb7f6d2
commit 3ff243b446
2 changed files with 7 additions and 10 deletions

View File

@ -5,28 +5,27 @@ export default {
</script> </script>
<script setup lang="ts"> <script setup lang="ts">
import { inject, Ref, computed, ref } from "vue"; import { inject, Ref, computed, ref, ComputedRef, WritableComputedRef } from "vue";
const props = defineProps<{ const props = defineProps<{
id: string; id: string;
}>(); }>();
const active = inject("active"); const active = inject("active") as WritableComputedRef<string>;
const slotsChange: Ref<boolean> = inject("slotsChange") as Ref<boolean>; const slotsChange: Ref<boolean> = inject("slotsChange") as Ref<boolean>;
slotsChange.value = !slotsChange.value; slotsChange.value = !slotsChange.value;
const anim = inject("anim"); const anim = inject("anim") as ComputedRef<string>;
const item = ref(); const item = ref();
const getStyle = computed<any>(() => { const getStyle = computed<any>(() => {
if (item.value) { if (item.value) {
let allChild = item.value.parentNode.children; let allChild = item.value.parentNode.children;
let allChildNum = allChild.length; let allChildNum = allChild.length;
let activeIndex, let activeIndex = 0;
currentIndex = 0; let currentIndex = 0;
for (let index = 0; index < allChild.length; index++) { for (let index = 0; index < allChild.length; index++) {
const element = allChild[index]; const element = allChild[index];
// @ts-ignore
if (element.getAttribute("data-id") === active.value) { if (element.getAttribute("data-id") === active.value) {
activeIndex = index; activeIndex = index;
} }
@ -34,13 +33,10 @@ const getStyle = computed<any>(() => {
currentIndex = index; currentIndex = index;
} }
} }
// @ts-ignore
let prevIndex = activeIndex > 0 ? activeIndex - 1 : allChildNum - 1; let prevIndex = activeIndex > 0 ? activeIndex - 1 : allChildNum - 1;
// @ts-ignore
let nextIndex = activeIndex + 1 < allChildNum ? activeIndex + 1 : 0; let nextIndex = activeIndex + 1 < allChildNum ? activeIndex + 1 : 0;
// @ts-ignore
let animation = anim.value; let animation = anim.value;
//
if (activeIndex === currentIndex) { if (activeIndex === currentIndex) {
if (animation === "updown") { if (animation === "updown") {
return { return {

View File

@ -33,6 +33,7 @@ layui - vue谐音类 UI) 是 一 套 Vue 3.0 的 桌 面 端 组 件 库 ,
::: title 如何贡献 ::: title 如何贡献
::: :::
<br>
<lay-timeline> <lay-timeline>
<lay-timeline-item simple>欢迎在<a href="https://github.com/layui/layui-vue/issues/new">提交问题</a>上向我们反馈。欢迎功能请求。如果您想贡献,请查看<a href="https://gitee.com/layui/layui-vue/blob/next/CONTRIBUTING.md">快速指南</a></lay-timeline-item> <lay-timeline-item simple>欢迎在<a href="https://github.com/layui/layui-vue/issues/new">提交问题</a>上向我们反馈。欢迎功能请求。如果您想贡献,请查看<a href="https://gitee.com/layui/layui-vue/blob/next/CONTRIBUTING.md">快速指南</a></lay-timeline-item>
<lay-timeline-item simple>如果您有什么想聊的,请随时加入我们的<a href="https://gitter.im/layui-vue/community">交流群</a></lay-timeline-item> <lay-timeline-item simple>如果您有什么想聊的,请随时加入我们的<a href="https://gitter.im/layui-vue/community">交流群</a></lay-timeline-item>