Nuxt/app/components/nuxt-child.js

65 lines
1.4 KiB
JavaScript
Raw Normal View History

2016-12-16 16:45:47 +00:00
import Vue from 'vue'
const transitionsKeys = [
'name',
'mode',
'css',
'type',
2017-03-24 02:00:35 +00:00
'duration',
2016-12-16 16:45:47 +00:00
'enterClass',
'leaveClass',
'enterActiveClass',
2017-01-02 17:05:53 +00:00
'enterActiveClass',
'leaveActiveClass',
'enterToClass',
'leaveToClass'
2016-12-16 16:45:47 +00:00
]
const listenersKeys = [
'beforeEnter',
'enter',
'afterEnter',
'enterCancelled',
'beforeLeave',
'leave',
'afterLeave',
'leaveCancelled'
]
export default {
name: 'nuxt-child',
functional: true,
render (h, { parent, data }) {
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
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
}
})
return h('transition', {
props: transitionProps,
on: listeners
}, [
h('router-view', data)
])
}
}