mirror of
https://gitee.com/ant-design-vue/ant-design-vue.git
synced 2024-12-05 05:29:01 +08:00
24 lines
744 B
TypeScript
24 lines
744 B
TypeScript
import { filterEmpty } from './props-util';
|
||
import { cloneVNode, VNode } from 'vue';
|
||
import warning from './warning';
|
||
|
||
export function cloneElement(vnode: VNode, nodeProps = {}, override = true) {
|
||
let ele = vnode;
|
||
if (Array.isArray(vnode)) {
|
||
ele = filterEmpty(vnode)[0];
|
||
}
|
||
if (!ele) {
|
||
return null;
|
||
}
|
||
const node = cloneVNode(ele, nodeProps);
|
||
|
||
// cloneVNode内部是合并属性,这里改成覆盖属性
|
||
node.props = override ? { ...node.props, ...nodeProps } : node.props;
|
||
warning(typeof node.props!.class !== 'object', 'class must be string');
|
||
return node;
|
||
}
|
||
|
||
export function cloneVNodes(vnodes: VNode[], nodeProps = {}, override = true) {
|
||
return vnodes.map(vnode => cloneElement(vnode, nodeProps, override));
|
||
}
|