✨(component): [tabitem] title 支持渲染函数
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -4,7 +4,7 @@ export const TabInjectKey = Symbol("layuiTab");
|
||||
|
||||
export interface TabData {
|
||||
id: string;
|
||||
title?: string;
|
||||
title?: string | Function;
|
||||
closable?: string | boolean;
|
||||
slots: Slots;
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ import { TabInjectKey, TabsContext } from "../tab/interface";
|
||||
|
||||
export interface LayTabItemProps {
|
||||
id: string;
|
||||
title: string;
|
||||
title?: string | Function;
|
||||
closable?: boolean | string;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user