UNPKG

element-plus-jsx

Version:

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

37 lines (35 loc) 1.14 kB
const GLOBAL_CONFIG_NAME = '$el-element-jsx'; const setGlobalConfig = (app, extract) => { app.config.globalProperties[GLOBAL_CONFIG_NAME] = { ...(app.config.globalProperties[GLOBAL_CONFIG_NAME] ?? {}), ...extract }; }; const getConfig = (instance, key) => { return instance.appContext.config.globalProperties[GLOBAL_CONFIG_NAME]?.[key]; }; const installPlugins = (args, useKey) => { let pluginReturn = args[useKey]; args.plugins.forEach((fn) => { pluginReturn = fn(Object.assign(args, { [useKey]: pluginReturn })); }); return pluginReturn; }; const transWidth = (width) => { if (typeof width === 'number') { return `${width}%`; } return width; }; const _get = (obj, path) => { return path.split('.').reduce((acc, key) => acc?.[key], obj); }; const _set = (obj, path, value) => { const keys = path.split('.'); const lastKey = keys.pop(); const lastObj = keys.reduce((acc, key) => { return acc[key] || (acc[key] = {}); }, obj); lastObj[lastKey] = value; }; export { _get, _set, getConfig, installPlugins, setGlobalConfig, transWidth };