Answer the question
In order to leave comments, you need to log in
How to create tabs in vue?
I want to create such tabs:
So that when the active button is changed, the line moves (travels) to the active button. But I don’t understand how to do this, it’s bad practice to work with dom directly, but I can’t even imagine how to do it using vue
Answer the question
In order to leave comments, you need to log in
working with dom directly is bad practice
props: [ 'items', 'value' ],
data: () => ({
sliderStyles: null,
}),
<ul class="tabs">
<li
v-for="n in items"
:key="n.value"
@click="$emit('input', n.value)"
class="tabs-item"
>{{ n.text }}</li>
</ul>
<div
class="tabs-slider"
:style="sliderStyles"
></div>
.tabs-slider
) element absolute positioning and a transition. mounted() {
this.$watch(
'value',
value => {
const index = this.items.findIndex(n => n.value === value);
const el = this.$el.querySelectorAll('.tabs-item')[index];
this.sliderStyles = el
? {
left: `${el.offsetLeft}px`,
width: `${el.offsetWidth}px`,
}
: null;
},
{
immediate: true,
}
);
},
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question