(component): [tabitem] title 支持渲染函数

This commit is contained in:
sight
2022-08-27 20:41:06 +08:00
parent 8820748d8c
commit f30012c852
4 changed files with 38 additions and 13 deletions

View File

@@ -8,7 +8,6 @@ export default {
import "./index.less";
import { LayIcon } from "@layui/icons-vue";
import tabItem from "../tabItem/index.vue";
import RenderTitle from "./renderTitle.vue";
import RenderFunction from "../_components/renderFunction";
import {
Component,
@@ -26,6 +25,7 @@ import {
reactive,
h,
createTextVNode,
isVNode,
} from "vue";
import { useResizeObserver } from "@vueuse/core";
import { TabData, TabInjectKey } from "./interface";
@@ -268,9 +268,18 @@ const update = () => {
};
const renderTabChild = (child: TabData) => {
return child.slots?.title
? () => h("span", child.slots?.title && child.slots.title())
: () => createTextVNode(child.title);
if (child.slots?.title){
return () => h("span", child.slots?.title && child.slots.title())
}
if (typeof child.title === "function"){
// @ts-ignore
return () => child.title();
} else if (typeof child.title === "string"){
return () => createTextVNode(child.title as string);
}
};
useResizeObserver(navRef, update);

View File

@@ -4,7 +4,7 @@ export const TabInjectKey = Symbol("layuiTab");
export interface TabData {
id: string;
title?: string;
title?: string | Function;
closable?: string | boolean;
slots: Slots;
}

View File

@@ -20,7 +20,7 @@ import { TabInjectKey, TabsContext } from "../tab/interface";
export interface LayTabItemProps {
id: string;
title: string;
title?: string | Function;
closable?: boolean | string;
}