fix
parent
13d5f32bd8
commit
d1a8d0d8c3
|
@ -1,7 +1,8 @@
|
||||||
export default (node, props) => {
|
export default (node, nodeProps) => {
|
||||||
|
const { props, style, class: cls, attrs, key } = nodeProps
|
||||||
if (node.componentOptions) {
|
if (node.componentOptions) {
|
||||||
const propsData = node.componentOptions.propsData
|
const propsData = node.componentOptions.propsData
|
||||||
Object.assign(propsData, props)
|
Object.assign(propsData, nodeProps)
|
||||||
}
|
}
|
||||||
return node
|
return node
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
||||||
|
}
|
|
@ -2,7 +2,7 @@
|
||||||
import PropTypes from 'vue-types'
|
import PropTypes from 'vue-types'
|
||||||
import align from 'dom-align'
|
import align from 'dom-align'
|
||||||
import addEventListener from '../_util/Dom/addEventListener'
|
import addEventListener from '../_util/Dom/addEventListener'
|
||||||
import cloneElement from '../_util/cloneElement'
|
import { cloneElement } from '../_util/vnode.js'
|
||||||
import isWindow from './isWindow'
|
import isWindow from './isWindow'
|
||||||
function noop () {
|
function noop () {
|
||||||
}
|
}
|
||||||
|
@ -106,7 +106,6 @@ export default {
|
||||||
},
|
},
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
console.log(4)
|
|
||||||
const { childrenProps } = this.$props
|
const { childrenProps } = this.$props
|
||||||
const child = this.$slots.default[0]
|
const child = this.$slots.default[0]
|
||||||
if (childrenProps) {
|
if (childrenProps) {
|
||||||
|
@ -116,7 +115,7 @@ export default {
|
||||||
newProps[prop] = this.props[childrenProps[prop]]
|
newProps[prop] = this.props[childrenProps[prop]]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return cloneElement(child, newProps)
|
return cloneElement(child, { props: newProps })
|
||||||
}
|
}
|
||||||
return child
|
return child
|
||||||
},
|
},
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
import Star from './Star.vue'
|
import Star from './Star.vue'
|
||||||
import Icon from '../icon'
|
import Icon from '../icon'
|
||||||
import { getOffsetLeft, deepClone } from './util'
|
import { getOffsetLeft, deepClone } from './util'
|
||||||
|
import { cloneVNodes } from '../_util/vnode'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'Rate',
|
name: 'Rate',
|
||||||
|
@ -116,7 +117,7 @@ export default {
|
||||||
onClick={this.onClick}
|
onClick={this.onClick}
|
||||||
onHover={this.onHover}
|
onHover={this.onHover}
|
||||||
key={i}>
|
key={i}>
|
||||||
{(this.hasDefaultSlot) ? (deepClone(this.$slots.default, createElement)) : this.character}
|
{(this.hasDefaultSlot) ? (cloneVNodes(this.$slots.default, true)) : this.character}
|
||||||
</Star>
|
</Star>
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<script>
|
<script>
|
||||||
import { deepClone } from './util'
|
import { cloneVNodes } from '../_util/vnode'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'Star',
|
name: 'Star',
|
||||||
|
@ -41,7 +41,7 @@ export default {
|
||||||
{this.$slots.default}
|
{this.$slots.default}
|
||||||
</div>
|
</div>
|
||||||
<div class={`${this.prefixCls}-second`}>
|
<div class={`${this.prefixCls}-second`}>
|
||||||
{deepClone(this.$slots.default, createElement)}
|
{cloneVNodes(this.$slots.default, true)}
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue