ant-design-vue/components/_util/vnode.js

18 lines
452 B
JavaScript
Raw Normal View History

2020-06-10 18:21:16 +08:00
import { filterEmpty } from './props-util';
import { cloneVNode } from 'vue';
2019-07-24 19:21:27 +08:00
2020-06-10 18:21:16 +08:00
export function cloneElement(n, nodeProps = {}, override = true) {
2019-01-12 11:33:27 +08:00
let ele = n;
2018-01-29 18:57:20 +08:00
if (Array.isArray(n)) {
2019-01-12 11:33:27 +08:00
ele = filterEmpty(n)[0];
2018-01-29 18:57:20 +08:00
}
if (!ele) {
2019-01-12 11:33:27 +08:00
return null;
2018-01-29 18:57:20 +08:00
}
2020-06-10 18:21:16 +08:00
const node = cloneVNode(ele, nodeProps);
2018-03-03 19:14:03 +08:00
2020-06-10 18:21:16 +08:00
// cloneVNode内部是合并属性这里改成覆盖属性
node.props = override ? { ...node.props, ...nodeProps } : node.props;
2019-01-12 11:33:27 +08:00
return node;
2017-12-14 12:13:15 +08:00
}