Nuxt/lib/app/components/nuxt-child.js

92 lines
2.0 KiB
JavaScript
Raw Normal View History

2016-12-16 16:45:47 +00:00
export default {
name: 'nuxt-child',
functional: true,
render (h, { parent, data }) {
2017-09-08 10:42:00 +00:00
const nuxt = parent.$root.nuxt
const component = parent.$route.matched[0].components.default
const layoutUid = parent._uid
const layoutName = component.options ? component.options.layout : null
2017-09-09 11:12:07 +00:00
// If we're changing layout render the stored vnode
2017-09-08 10:42:00 +00:00
if (nuxt._layoutUid === layoutUid &&
2017-10-07 14:59:36 +00:00
nuxt._layoutName !== layoutName
) {
return nuxt._childVnode
}
2017-09-08 10:42:00 +00:00
nuxt._layoutUid = layoutUid
nuxt._layoutName = layoutName
2016-12-16 16:45:47 +00:00
data.nuxtChild = true
const _parent = parent
2016-12-16 16:45:47 +00:00
const transitions = parent.$nuxt.nuxt.transitions
const defaultTransition = parent.$nuxt.nuxt.defaultTransition
let depth = 0
while (parent) {
if (parent.$vnode && parent.$vnode.data.nuxtChild) {
depth++
}
parent = parent.$parent
}
data.nuxtChildDepth = depth
2017-10-07 14:59:36 +00:00
2016-12-16 16:45:47 +00:00
const transition = transitions[depth] || defaultTransition
let transitionProps = {}
transitionsKeys.forEach((key) => {
if (typeof transition[key] !== 'undefined') {
transitionProps[key] = transition[key]
}
})
let listeners = {}
listenersKeys.forEach((key) => {
if (typeof transition[key] === 'function') {
listeners[key] = transition[key].bind(_parent)
2016-12-16 16:45:47 +00:00
}
})
2017-09-08 10:42:00 +00:00
2017-09-09 11:12:07 +00:00
nuxt._childVnode = h('transition', {
2016-12-16 16:45:47 +00:00
props: transitionProps,
on: listeners
}, [
h('router-view', data)
])
2017-09-08 10:42:00 +00:00
2017-09-09 11:12:07 +00:00
return nuxt._childVnode
2016-12-16 16:45:47 +00:00
}
}
2017-10-07 14:59:36 +00:00
const transitionsKeys = [
'name',
'mode',
'appear',
'css',
'type',
'duration',
'enterClass',
'leaveClass',
'appearClass',
'enterActiveClass',
'enterActiveClass',
'leaveActiveClass',
'appearActiveClass',
'enterToClass',
'leaveToClass',
'appearToClass'
]
const listenersKeys = [
'beforeEnter',
'enter',
'afterEnter',
'enterCancelled',
'beforeLeave',
'leave',
'afterLeave',
'leaveCancelled',
'beforeAppear',
'appear',
'afterAppear',
'appearCancelled'
]