vuejs2 - Vue component data not updating from props -
i'm building spa scroll navigation being populated menu items based on section components.
in home.vue i'm importing scrollnav , sections this:
<template> <div class="front-page"> <scroll-nav v-if="scrollnavshown" @select="changesection" :active-section="activeitem" :items="sections"></scroll-nav> <fp-sections @loaded="buildnav" :active="activeitem"></fp-sections> </div> </template> <script> import scrollnav '.././components/scrollnav.vue' import fpsections './fpsections.vue' export default { data() { return { scrollnavshown: true, activeitem: 'sectionone', scrollposition: 0, sections: [] } }, methods: { buildnav(sections) { this.sections = sections; console.log(this.sections) }, changesection(e) { this.activeitem = e }, }, components: { scrollnav, fpsections } } </script> this.sections empty, since i'm populating array data individual sections in fpsections.vue:
<template> <div class="fp-sections"> <keep-alive> <transition @enter="enter" @leave="leave" :css="false" > <component :is="activesection"></component> </transition> </keep-alive> </div> </template> <script> import sectionone './sections/sectionone.vue' import sectiontwo './sections/sectiontwo.vue' import sectionthree './sections/sectionthree.vue' export default { components: { sectionone, sectiontwo, sectionthree }, props: { active: string }, data() { return { activesection: this.active, sections: [] } }, mounted() { this.buildnav(); }, methods: { buildnav() { let _components = this.$options.components; for(let prop in _components) { if(!_components[prop].hasownproperty('data')) continue; this.sections.push({ title: _components[prop].data().title, name: _components[prop].data().name }) } this.$emit('loaded', this.sections) }, enter(el) { twm.to(el, .2, { autoalpha : 1 }) }, leave(el, done) { twm.to(el, .2, { autoalpha : 0 }) } } } </script> the buildnav method loops through individual components' data , pushes scoped this.sections array emitted home.vue
back in home.vue this.sections populated data emitted fpsections.vue , passed prop.
when inspect vue devtools props passed down correctly data not update.
what missing here? data should react props when updated in parent right?
:active="activeitem" this calld "dynamic prop" not dynamic data. set in once "oninit". reactivity can
computed:{ activesection(){ return this.active;} } or
watch: { active(){ //do } }
Comments
Post a Comment