UNPKG

element-plus-jsx

Version:

基于 Element Plus 扩展 JSX 语法的组件库

62 lines (59 loc) 1.7 kB
import { defineComponent, shallowRef, getCurrentInstance, inject, onBeforeMount, createVNode, mergeProps, shallowReactive } from 'vue'; import { ElTable, ElTableColumn } from 'element-plus'; import { useFnOrRefProp } from '../hooks.js'; import { getConfig, installPlugins } from '../_utils/index.js'; import { providerInjectKey } from '../provider/context.js'; var _sfc_main = /* @__PURE__ */ defineComponent({ props: { data: { type: Array, default: () => [] }, plugins: { type: Array, default: () => [] }, columns: { type: Array, default: () => [], required: true } }, setup(props, ctx) { const tableRef = shallowRef(); const plugins = getConfig(getCurrentInstance(), 'tablePlugins') || []; const { tableProps = {}, tablePlugins = [] } = inject(providerInjectKey, {}); onBeforeMount(() => { plugins.push(...props.plugins, ...tablePlugins); }); ctx.expose({ tableRef }); return () => createVNode(ElTable, mergeProps({ "ref": tableRef }, { ...tableProps, ...ctx.attrs }, { "data": props.data, "element-loading-text": ctx.attrs.elementLoadingText || 'Loading ...' }), { default: () => [shallowReactive(installPlugins({ ...props, ...ctx, tableRef, plugins }, 'columns')).filter(res => useFnOrRefProp(res.show) ?? true).map((column, index) => createVNode(ElTableColumn, mergeProps({ "key": index }, column), { default: column.slots?.default, header: column.slots?.header }))], ...ctx.slots }); } }); export { _sfc_main as default };