Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

222
Visualizações
Toggle classes in different components in Nuxt.js

Let's say I created a plugin in my Nuxt app:

  plugins: [
    '~/plugins/toggler',
  ],

which contains:

import Vue from 'vue'

Vue.mixin({
  data() {
    return {
      isActive: false
    }
  },
  methods: {
    toggler() {
      this.isActive = !this.isActive
    },
  },
})

I would like to toggle classes on elements on different components, like:

<div :class="{ 'is-active': isActive }"></div>

and it's correctly triggered via a button:

    <button @click.prevent="toggler" />

However, this only change the class on other elements inside the same .vue component where the button is.

Other elements with the same :class="{ 'is-active': isActive }" in different .vue components aren't affected, unless I add a button in those components too.

Here's a sandbox: https://codesandbox.io/s/tender-http-fqlx5

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Why you create a mixin in a plugin?

Create and usage mixin:

create:

In the mixins folder inside You're creating a mixin file (example.js)

usage:

import into the component:

import example from '~/mixins/example'

Mixin definition into component into script:

export default {
  mixins: [example],
  data() {
    return {}
  },
  computed: {},
  methods: {}
}

This allows it to be reused into any component.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda