mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-30 17:37:14 +00:00
9c1e0d1743
Co-authored-by: Clark Du <clark.duxin@gmail.com> Co-authored-by: Pooya Parsa <pooya@pi0.ir>
91 lines
2.1 KiB
JavaScript
91 lines
2.1 KiB
JavaScript
export default {
|
|
name: 'nuxt-child',
|
|
functional: true,
|
|
props: ['keepAlive', 'keepAliveProps'],
|
|
render (h, { parent, data, props }) {
|
|
data.nuxtChild = true
|
|
const _parent = parent
|
|
const transitions = parent.<%= globals.nuxt %>.nuxt.transitions
|
|
const defaultTransition = parent.<%= globals.nuxt %>.nuxt.defaultTransition
|
|
|
|
let depth = 0
|
|
while (parent) {
|
|
if (parent.$vnode && parent.$vnode.data.nuxtChild) {
|
|
depth++
|
|
}
|
|
parent = parent.$parent
|
|
}
|
|
data.nuxtChildDepth = depth
|
|
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)
|
|
}
|
|
})
|
|
// Add triggerScroll event on beforeEnter (fix #1376)
|
|
const beforeEnter = listeners.beforeEnter
|
|
listeners.beforeEnter = (el) => {
|
|
// Ensure to trigger scroll event after calling scrollBehavior
|
|
window.<%= globals.nuxt %>.$nextTick(() => {
|
|
window.<%= globals.nuxt %>.$emit('triggerScroll')
|
|
})
|
|
if (beforeEnter) return beforeEnter.call(_parent, el)
|
|
}
|
|
|
|
let routerView = [
|
|
h('router-view', data)
|
|
]
|
|
if (typeof props.keepAlive !== 'undefined') {
|
|
routerView = [
|
|
h('keep-alive', { props: props.keepAliveProps }, routerView)
|
|
]
|
|
}
|
|
return h('transition', {
|
|
props: transitionProps,
|
|
on: listeners
|
|
}, routerView)
|
|
}
|
|
}
|
|
|
|
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'
|
|
]
|