M
M
Maxim2021-11-20 17:23:48
Vue.js
Maxim, 2021-11-20 17:23:48

Is it possible to add .active to a marker using router-link?

.navigation
    ul
      li
        router-link(:to="{ name: 'tasks'} ") Tasks
      li
        router-link(:to="{ name: 'kanban'}") Kanban
      li
        router-link(:to="{ name: 'activity'}") Activity
      li
        router-link(:to="{ name: 'calendar'}") Calendar
      li
        router-link(:to="{ name: 'files'}") Files
  .marker
    .selecttasks
      span
    .selectkanban
      span
    .selectactivity
      span.third-marker( )
    .selectcalendar
      span.fourth-marker( )
    .selectfiles
      span

Answer the question

In order to leave comments, you need to log in

2 answer(s)
0
0xD34F, 2021-11-20
@0xD34F Vue.js

data: () => ({
  links: [ 'tasks', 'kanban', 'activity', 'calendar', 'files' ],
}),

ul
  li(v-for="n in links")
    router-link(:to="{ name: n }") {{ n }}
.marker
  div(v-for="n in links" :class="[ `select${n}`, $route.name === n ? 'active' : '' ]")
    span

It is not clear why it is needed - they would remove these "markers", and stylize the links themselves, there is no need to add any classes manually, everything is already there .

A
Aetae, 2021-11-21
@Aetae

Maybe you should read the documentation, which even has just such an example ?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question