I want to add component in random position (not random actually, based on some logic) based on click of other elements.
In jQuery, we can achieve that by $('#someId').append('element')
or by $('#someId').find('.someClass').after('element')
What I want achieve (jquery version): jsfiddle
How to do that in Vue?
N.B: This couldn't be achieved by v-for
as all elements won't appear sequentially or in the same place. Also, components should not be appeared on initialization as this is dynamic.
If this is about arranging that which component will appear after another. Let me assume I have all those components in an array and you can re-arrange those in the array as par your logic, and you can use special attribute: is to render those component.
Here in sample I have an array of components and I use
v-for
to render those one after another:See fiddle here.
HTML:
JS:
Can you provide an example of your parent component when you are traversing your array/list to map your element with a component? (just to understand your use case)
You could use
v-for
but on multiple arrays generated by some computed properties in the place you want to display them (if the places you wanna display components are not also randomly chosen).