2016-12-16 16:45:47 +00:00
|
|
|
export default {
|
|
|
|
name: 'nuxt-child',
|
|
|
|
functional: true,
|
2018-01-17 08:39:34 +00:00
|
|
|
props: ['keepAlive'],
|
|
|
|
render (h, { parent, data, props }) {
|
2016-12-16 16:45:47 +00:00
|
|
|
data.nuxtChild = true
|
2017-06-11 23:43:39 +00:00
|
|
|
const _parent = parent
|
2016-12-16 16:45:47 +00:00
|
|
|
const transitions = parent.$nuxt.nuxt.transitions
|
|
|
|
const defaultTransition = parent.$nuxt.nuxt.defaultTransition
|
2017-11-06 17:30:15 +00:00
|
|
|
|
2016-12-16 16:45:47 +00:00
|
|
|
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') {
|
2017-06-11 23:43:39 +00:00
|
|
|
listeners[key] = transition[key].bind(_parent)
|
2016-12-16 16:45:47 +00:00
|
|
|
}
|
|
|
|
})
|
2018-01-31 15:13:28 +00:00
|
|
|
// Add triggerScroll event on beforeEnter (fix #1376)
|
|
|
|
let beforeEnter = listeners.beforeEnter
|
|
|
|
listeners.beforeEnter = (el) => {
|
2018-06-21 06:22:52 +00:00
|
|
|
// Ensure to trigger scroll event after calling scrollBehavior
|
|
|
|
window.$nuxt.$nextTick(() => {
|
|
|
|
window.$nuxt.$emit('triggerScroll')
|
|
|
|
})
|
2018-01-31 15:13:28 +00:00
|
|
|
if (beforeEnter) return beforeEnter.call(_parent, el)
|
|
|
|
}
|
2017-09-08 10:42:00 +00:00
|
|
|
|
2018-01-17 08:39:34 +00:00
|
|
|
let routerView = [
|
|
|
|
h('router-view', data)
|
|
|
|
]
|
|
|
|
if (typeof props.keepAlive !== 'undefined') {
|
|
|
|
routerView = [
|
|
|
|
h('keep-alive', routerView)
|
|
|
|
]
|
|
|
|
}
|
2017-11-06 17:30:15 +00:00
|
|
|
return h('transition', {
|
2016-12-16 16:45:47 +00:00
|
|
|
props: transitionProps,
|
|
|
|
on: listeners
|
2018-01-17 08:39:34 +00:00
|
|
|
}, routerView)
|
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'
|
|
|
|
]
|