S
S
stanislavkm2022-04-11 21:16:32
Vue.js
stanislavkm, 2022-04-11 21:16:32

How to add a class to an element described in app but in a different router-view element in vue 3?

<template>
  <header>
...
  </header>
      <router-view/>
  <footer>
...
  </footer>
</template>


There is such a structure, and when substituting a certain page in the router-view, it is necessary that a certain class be substituted for the header and footer. How can this be implemented?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
LJ322, 2022-04-11
@stanislavkm

Via computed property

<template>
  <header :class="pageClass">
...
  </header>
      <router-view/>
  <footer :class="pageClass">
...
  </footer>
</template>

<script>
export default {
  computed: {
    pageClass() {
      return {
        'page-class': this.$route.path === '/page',
      }
    }
  }
}
</script>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question