Browse Source

fix

pull/9/head
tangjinzhou 7 years ago
parent
commit
d1a8d0d8c3
  1. 5
      components/_util/cloneElement.js
  2. 46
      components/_util/vnode.js
  3. 5
      components/align/Align.vue
  4. 3
      components/rate/Rate.vue
  5. 4
      components/rate/Star.vue

5
components/_util/cloneElement.js

@ -1,7 +1,8 @@
export default (node, props) => {
export default (node, nodeProps) => {
const { props, style, class: cls, attrs, key } = nodeProps
if (node.componentOptions) {
const propsData = node.componentOptions.propsData
Object.assign(propsData, props)
Object.assign(propsData, nodeProps)
}
return node
}

46
components/_util/vnode.js

@ -0,0 +1,46 @@
export function cloneVNode (vnode, deep) {
const cloned = new vnode.constructor(
vnode.tag,
vnode.data,
vnode.children,
vnode.text,
vnode.elm,
vnode.context,
vnode.componentOptions,
vnode.asyncFactory
)
cloned.ns = vnode.ns
cloned.isStatic = vnode.isStatic
cloned.key = vnode.key
cloned.isComment = vnode.isComment
cloned.isCloned = true
if (deep && vnode.children) {
cloned.children = cloneVNodes(vnode.children)
}
return cloned
}
export function cloneVNodes (vnodes, deep) {
const len = vnodes.length
const res = new Array(len)
for (let i = 0; i < len; i++) {
res[i] = cloneVNode(vnodes[i], deep)
}
return res
}
export function cloneElement (node, nodeProps) {
const { props, key } = nodeProps
if (node.componentOptions) {
Object.assign(node.componentOptions.propsData, props)
}
if (node.data) {
const data = node.data
const { style = data.style, class: cls = data.class, attrs = data.attrs } = nodeProps
Object.assign(node.data, { style, attrs, class: cls })
}
if (key !== undefined) {
node.key = key
}
return node
}

5
components/align/Align.vue

@ -2,7 +2,7 @@
import PropTypes from 'vue-types'
import align from 'dom-align'
import addEventListener from '../_util/Dom/addEventListener'
import cloneElement from '../_util/cloneElement'
import { cloneElement } from '../_util/vnode.js'
import isWindow from './isWindow'
function noop () {
}
@ -106,7 +106,6 @@ export default {
},
render () {
console.log(4)
const { childrenProps } = this.$props
const child = this.$slots.default[0]
if (childrenProps) {
@ -116,7 +115,7 @@ export default {
newProps[prop] = this.props[childrenProps[prop]]
}
}
return cloneElement(child, newProps)
return cloneElement(child, { props: newProps })
}
return child
},

3
components/rate/Rate.vue

@ -2,6 +2,7 @@
import Star from './Star.vue'
import Icon from '../icon'
import { getOffsetLeft, deepClone } from './util'
import { cloneVNodes } from '../_util/vnode'
export default {
name: 'Rate',
@ -116,7 +117,7 @@ export default {
onClick={this.onClick}
onHover={this.onHover}
key={i}>
{(this.hasDefaultSlot) ? (deepClone(this.$slots.default, createElement)) : this.character}
{(this.hasDefaultSlot) ? (cloneVNodes(this.$slots.default, true)) : this.character}
</Star>
)
})

4
components/rate/Star.vue

@ -1,5 +1,5 @@
<script>
import { deepClone } from './util'
import { cloneVNodes } from '../_util/vnode'
export default {
name: 'Star',
@ -41,7 +41,7 @@ export default {
{this.$slots.default}
</div>
<div class={`${this.prefixCls}-second`}>
{deepClone(this.$slots.default, createElement)}
{cloneVNodes(this.$slots.default, true)}
</div>
</li>
)

Loading…
Cancel
Save