2018-10-24 13:46:06 +00:00
|
|
|
<%= isTest ? '// @vue/component' : '' %>
|
2016-12-16 16:45:47 +00:00
|
|
|
export default {
|
2018-11-24 18:49:19 +00:00
|
|
|
name: 'NuxtChild',
|
2016-12-16 16:45:47 +00:00
|
|
|
functional: true,
|
2018-10-24 13:46:06 +00:00
|
|
|
props: {
|
|
|
|
nuxtChildKey: {
|
|
|
|
type: String,
|
|
|
|
default: ''
|
|
|
|
},
|
2018-12-11 10:11:15 +00:00
|
|
|
keepAlive: Boolean,
|
2019-01-06 07:56:59 +00:00
|
|
|
keepAliveProps: {
|
|
|
|
type: Object,
|
|
|
|
default: undefined
|
|
|
|
}
|
2018-10-24 13:46:06 +00:00
|
|
|
},
|
2020-02-04 18:36:22 +00:00
|
|
|
render (_, { parent, data, props }) {
|
|
|
|
const h = parent.$createElement
|
2019-09-05 15:15:27 +00:00
|
|
|
<% if (features.transitions) { %>
|
2016-12-16 16:45:47 +00:00
|
|
|
data.nuxtChild = true
|
2017-06-11 23:43:39 +00:00
|
|
|
const _parent = parent
|
2018-10-09 12:07:23 +00:00
|
|
|
const transitions = parent.<%= globals.nuxt %>.nuxt.transitions
|
|
|
|
const defaultTransition = parent.<%= globals.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
|
2018-10-24 13:46:06 +00:00
|
|
|
const transitionProps = {}
|
2016-12-16 16:45:47 +00:00
|
|
|
transitionsKeys.forEach((key) => {
|
|
|
|
if (typeof transition[key] !== 'undefined') {
|
|
|
|
transitionProps[key] = transition[key]
|
|
|
|
}
|
|
|
|
})
|
2018-10-12 22:31:19 +00:00
|
|
|
|
2018-10-24 13:46:06 +00:00
|
|
|
const listeners = {}
|
2016-12-16 16:45:47 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
})
|
2020-02-04 18:36:22 +00:00
|
|
|
if (process.client) {
|
|
|
|
// 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)
|
|
|
|
}
|
2019-06-14 17:28:03 +00:00
|
|
|
}
|
2018-01-31 15:13:28 +00:00
|
|
|
}
|
2017-09-08 10:42:00 +00:00
|
|
|
|
2019-06-14 17:28:03 +00:00
|
|
|
// make sure that leave is called asynchronous (fix #5703)
|
|
|
|
if (transition.css === false) {
|
|
|
|
const leave = listeners.leave
|
|
|
|
|
2019-08-21 11:36:52 +00:00
|
|
|
// only add leave listener when user didnt provide one
|
|
|
|
// or when it misses the done argument
|
|
|
|
if (!leave || leave.length < 2) {
|
|
|
|
listeners.leave = (el, done) => {
|
|
|
|
if (leave) {
|
|
|
|
leave.call(_parent, el)
|
|
|
|
}
|
|
|
|
|
|
|
|
_parent.$nextTick(done)
|
|
|
|
}
|
2019-06-14 17:28:03 +00:00
|
|
|
}
|
|
|
|
}
|
2019-09-05 15:15:27 +00:00
|
|
|
<% } %>
|
2019-06-14 17:28:03 +00:00
|
|
|
let routerView = h('routerView', data)
|
|
|
|
|
2018-10-24 13:46:06 +00:00
|
|
|
if (props.keepAlive) {
|
2019-06-14 17:28:03 +00:00
|
|
|
routerView = h('keep-alive', { props: props.keepAliveProps }, [routerView])
|
2018-01-17 08:39:34 +00:00
|
|
|
}
|
2019-06-14 17:28:03 +00:00
|
|
|
|
2019-09-05 15:15:27 +00:00
|
|
|
<% if (features.transitions) { %>
|
2017-11-06 17:30:15 +00:00
|
|
|
return h('transition', {
|
2016-12-16 16:45:47 +00:00
|
|
|
props: transitionProps,
|
|
|
|
on: listeners
|
2019-06-14 17:28:03 +00:00
|
|
|
}, [routerView])
|
2019-09-05 15:15:27 +00:00
|
|
|
<% } else { %>
|
|
|
|
return routerView
|
|
|
|
<% } %>
|
2016-12-16 16:45:47 +00:00
|
|
|
}
|
|
|
|
}
|
2017-10-07 14:59:36 +00:00
|
|
|
|
2019-09-05 15:15:27 +00:00
|
|
|
<% if (features.transitions) { %>
|
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'
|
|
|
|
]
|
2019-09-05 15:15:27 +00:00
|
|
|
<% } %>
|