javascript - Is VueJS guaranteed to call mounted() in correct order? -
let's have basic page vuejs follows:
vue.component('child', { template: '<p>placed @ index {{index}}</p>', data() { return { index: 0 } }, mounted() { this.index = this.$parent.addelement(this); } }); new vue({ el: '#theparent', data() { return { allelements: [] } }, methods: { addelement(elem) { this.allelements.push(elem); return this.allelements.length - 1; } } });
<script src="https://cdn.jsdelivr.net/vue/2.3.2/vue.min.js"></script> <div id="theparent"> <child></child> <child></child> <child></child> </div>
the purpose of output illustrate @ index elements have been inserted at. use case requires elements added in same order appear in html. every time run page appears indeed happening output in order.
my question is: behavior guaranteed happen - vuejs execute mounted()
on components in order appear in html? if not, there alternate way guarantee added array in proper order?
Comments
Post a Comment