これは、どのコンポーネントが別のコンポーネントの後に現れるかを整理する場合です。私は配列内のすべてのコンポーネントを持っていると仮定し、配列内のロジックとしてそれらを再配置することができますし、特別な属性:isを使用してそれらのコンポーネントをレンダリングすることができます。
ここでは、試料中の私は、コンポーネントの配列を持っていると私は別の後に、それらのものをレンダリングするためにv-for
を使用します。
はフィドルhereを参照してください。
HTML:
<div id="app">
<h1>
Following are the components
</h1>
<div v-for="comp in compArray" :is="comp"></div>
<br>
<button @click="resuffle">
Resuffle
</button>
</div>
<template id="comp1">
<div>
<span>This is component 1</span>
</div>
</template>
<template id="comp2">
<div>
<span>This is component 2</span>
</div>
</template>
<template id="comp3">
<div>
<span>This is component 3</span>
</div>
</template>
JS:
Vue.component('comp1', {
template: '#comp1',
})
Vue.component('comp2', {
template: '#comp2',
})
Vue.component('comp3', {
template: '#comp3',
})
new Vue({
el: '#app',
data: {
compArray: ['comp1', 'comp2', 'comp3']
},
methods: {
resuffle: function() {
this.compArray.push(this.compArray[1])
this.compArray.splice(1,1)
}
},
})
あなたが、私はここから達成しようとしている何の詳細を取得することができます:http://stackoverflow.com/questions/41415523/how-to-insert-vue-component-in-dynamic-position とにかく、これはアイテムの配列ではありません。私は別の場所に(クリックされたパネルの行の後に)単一のコンポーネントを表示したい。 – Sovon