🐛(tree & carousel): 修复 tree 与 carousel 语法错误

更新文档
This commit is contained in:
就眠儀式 2022-06-17 20:15:06 +08:00
parent 83d4622df9
commit 79acc7b078
3 changed files with 17 additions and 23 deletions

View File

@ -15,8 +15,7 @@ import {
VNode,
Ref,
Component,
watch,
onMounted,
watch
} from "vue";
import CarouselItem from "../carouselItem/index.vue";
@ -75,7 +74,7 @@ const setItemInstanceBySlot = function (nodeList: VNode[]) {
});
};
watch(slotsChange, function () {
watch(slotsChange, () => {
childrens.value = [];
setItemInstanceBySlot((slot.default && slot.default()) as VNode[]);
});
@ -83,14 +82,13 @@ watch(slotsChange, function () {
provide("active", active);
provide("slotsChange", slotsChange);
//
const sub = function () {
for (var i = 0; i < childrens.value.length; i++) {
if (childrens.value[i].props.id === active.value) {
if (childrens.value[i].props?.id === active.value) {
if (i === 0) {
active.value = childrens.value[slots.length - 1].props.id;
active.value = childrens.value[slots.length - 1].props?.id;
} else {
active.value = childrens.value[i - 1].props.id;
active.value = childrens.value[i - 1].props?.id;
}
break;
}
@ -100,11 +98,11 @@ const sub = function () {
//
const add = function () {
for (var i = 0; i < childrens.value.length; i++) {
if (childrens.value[i].props.id === active.value) {
if (childrens.value[i].props?.id === active.value) {
if (i === childrens.value.length - 1) {
active.value = childrens.value[0].props.id;
active.value = childrens.value[0].props?.id;
} else {
active.value = childrens.value[i + 1].props.id;
active.value = childrens.value[i + 1].props?.id;
}
break;
}
@ -114,11 +112,11 @@ const add = function () {
//
const autoplay = () => {
for (var i = 0; i < childrens.value.length; i++) {
if (childrens.value[i].props.id === active.value) {
if (childrens.value[i].props?.id === active.value) {
if (i === childrens.value.length - 1) {
active.value = childrens.value[0].props.id;
active.value = childrens.value[0].props?.id;
} else {
active.value = childrens.value[i + 1].props.id;
active.value = childrens.value[i + 1].props?.id;
}
break;
}
@ -140,24 +138,21 @@ watch(
:lay-anim="anim"
:lay-indicator="indicator"
:lay-arrow="arrow"
:style="{ width: width, height: height }"
:style="{ 'width': width, 'height': height }"
>
<!-- 内容 -->
<div carousel-item>
<slot></slot>
</div>
<!-- 轮播 -->
<div class="layui-carousel-ind">
<ul>
<li
v-for="ss in childrens"
:key="ss"
:class="[ss.props.id === active ? 'layui-this' : '']"
@click.stop="change(ss.props.id)"
v-for="(ss, index) in childrens"
:key="index"
:class="[ss.props?.id === active ? 'layui-this' : '']"
@click.stop="change(ss.props?.id)"
></li>
</ul>
</div>
<!-- 操作 -->
<button class="layui-icon layui-carousel-arrow" lay-type="sub" @click="sub">
{{ anim === "updown" ? "" : "" }}
</button>

View File

@ -88,7 +88,7 @@ function handleClick(node: TreeData) {
:only-icon-control="onlyIconControl"
@node-click="handleClick"
>
<template v-if="slots.title" v-slot:title="{ data }">
<template v-if="slots.title">
<slot name="title" :data="data"></slot>
</template>
</tree-node>

View File

@ -38,7 +38,6 @@ export const useTree: UseTree = (props: TreeProps, emit: TreeEmits) => {
(list) => {
const { checkedKeys, expandKeys } = tree.getKeys();
emit("update:checkedKeys", checkedKeys);
// emit('update:expandKeys', expandKeys)
},
{ deep: true }
);