Answer the question
In order to leave comments, you need to log in
How to switch between components when clicking on a list using v-for?
I am learning vue. There is a video https://youtu.be/Q7CUJRbuZaU?t=2m43s
How to do the same using only not four links as in the video, but for example a list.
li.list-group-item(
v-for="item in items"
)
{{ item.name }}
var items = [
{ name: 'test1' },
{ name: 'test2' },
{ name: 'test3' }
]
Answer the question
In order to leave comments, you need to log in
You will need two properties - an array of component names and the name of the currently selected component:
data: () => ({
items: [ 'имя-компонента-1', 'имя-компонента-2', 'имя-компонента-3' ],
selected: null,
}),
<li
v-for="n in items"
v-text="n"
@click="selected = n"
></li>
<component v-if="selected" :is="selected"></component>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question