Fix re-usable component data

This commit is contained in:
Sébastien Chopin 2016-12-20 13:44:00 +01:00
parent 79fae6fe5c
commit 0fe34e0fb0

View File

@ -8,6 +8,7 @@ import { getMatchedComponents, getMatchedComponentsInstances, flatMapComponents,
const noopData = () => { return {} }
const noopFetch = () => {}
let _lastPaths = []
let _lastComponentsFiles = []
function mapTransitions(Components, to, from) {
return Components.map((Component) => {
@ -144,14 +145,15 @@ function render (to, from, next) {
function fixPrepatch (to, ___) {
Vue.nextTick(() => {
let instances = getMatchedComponentsInstances(to)
instances.forEach((instance, i) => {
if (!instance) return;
_lastComponentsFiles = instances.map((instance, i) => {
if (!instance) return '';
if (_lastPaths[i] === instance.constructor._path) {
let newData = instance.constructor.options.data()
for (let key in newData) {
Vue.set(instance.$data, key, newData[key])
}
}
return instance.constructor.options.__file
})
})
}
@ -281,6 +283,7 @@ Promise.all(resolveComponents)
if (Components.length) {
_app.setTransitions(mapTransitions(Components, router.currentRoute))
_lastPaths = router.currentRoute.matched.map((route) => compile(route.path)(router.currentRoute.params))
_lastComponentsFiles = Components.map((Component) => Component.options.__file)
}
_app.error = _app.$options._nuxt.error.bind(_app)
_app.$loading = {} // to avoid error while _app.$nuxt does not exist