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

326
Visualizações
Vue.js - How to prevent re-render whole component?

I want to prevent my whole component (a modal) re-render. When user login, my web application shows a modal including some messages. Once user clicks next, the content in this modal changes. However, the modal will shows the pop-up animation again. The modal use same modal, but change the content.

This is absolute how Vue works, however, if the firstPage changes, the modal pop-up again... How could I only re-render the content part, not the whole modal?

<template>
  <div>
    <b-modal v-model="modalShow">
       <p v-if="firstPage">Hello</p>
       <p v-else>{{content}}</p>
    </b-modal>
  </div>
</template>

<script>
  export default {
    data() {
      return {
        modalShow: false,
      }
    },
    computed() {
      content() {
        return this.$store.state.content
       },
     firstPage() {
        return this.$store.state.firstPage
      }
    }
  }
</script>
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

After reading your question I imagine you have an login button.. than you can do following - add a click event to your button like this:

<b-button @click="login = !login> LOGIN </b-button> //use this if you want to switch your modal each time on click
<b-button @click="login = false"> LOGIN </b-button> //use this if you only want to change it one time after click

Here you are switching your boolean if it's firstly true after clicking your button it will be false.

Than you have to define your property in your data return like this:

data() {
  return {
    login: true,
  }
}

and afterwards you can check it in your template, like you have done it before:

<p v-if="login == true">Login is true</p>
<p v-if="login == false">Login is false</p>

<!-- OR -->
<p v-if="login == true">Login is true</p>
<p v-else>Login is false</p>

You can also add a method to your click event and check it there if you don't want to have code like login = !login in your template!

Please let me know if this helps you!

about 4 years ago · Juan Pablo Isaza Relatório

0

The re-render issue is unlikely to be related to the children, could you eloborate the example more? As you can see in the example, content of the children changes without opening the modal second time, it should be related to unwanted change on the "modalShow", how and where are you changing this data.

window.onload = () => {
  new Vue({
    el: '#app',
    data() {
      return {
        modalShow: false,
        firstPage: true,
      }
    },
    methods: {
        toggle() {
            this.modalShow = !this.modalShow;
            setTimeout(() => this.firstPage = !this.firstPage, 300);
        }
    }
  })
}
<link href="https://unpkg.com/bootstrap-vue@2.21.2/dist/bootstrap-vue.css" rel="stylesheet"/>
<link href="https://unpkg.com/bootstrap@4.5.3/dist/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://unpkg.com/vue@2.6.12/dist/vue.min.js"></script>
<script src="https://unpkg.com/bootstrap-vue@2.21.2/dist/bootstrap-vue.js"></script>
<script src="https://unpkg.com/babel-polyfill/dist/polyfill.min.js"></script>

<div id="app">
  <div>
    <b-button @click="toggle">Launch demo modal</b-button>

    <b-modal v-model="modalShow">
      <p class="my-4" v-if="firstPage">1st Component</p>
      <p class="my-4" v-else>2nd Component</p>
    </b-modal>
  </div>
</div>

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