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

117
Visualizações
vue.js reactivity and data with mixin

I am trying to set a flag that can be a boolean value true or false based on certain conditions.

// main.js
new Vue({
    el: `#app`,
    render: h => h(App,{
      props:{
        todoID: this.dataset.id
      }
    })
  })

my App script

export default {
  name: 'App',
  props: {
    todoID: String,
  },
  data() {
    return {
      isDone: false // here is the initial flag
    }
  },
  ...

I created a mixin method

import Vue from "vue";

Vue.mixin({
    methods: {
        isCompleted() {
            if (myconditions){
                this.isDone = true; // I want to change the flag to true
            }
        },
    },
});

in my template if I do {{isDone}} I always get false, how can I change this to be reactive so it can be changed based on the conditions?

Here is a demo I created: https://codesandbox.io/embed/vigorous-bell-p1itu?fontsize=14&hidenavigation=1&theme=dark

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Vue.mixin({
    methods: {
        isCompleted(myconditions) {
            console.log(myconditions);
            console.log(typeof myconditions);
              return  this.isDone = myconditions; // I want to change the flag to true
            
        },
    },
});
new Vue({
    el: '#vue-app',
    data: {
        isDone: false 
    }
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>

        <div id="vue-app">
            <p> result = {{ isCompleted(true) }}</p>
        </div>
    </body>

over 4 years ago · Santiago Trujillo 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