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
Updating data according to props value in Vue file returning not defined error message

I am trying to change the data depending on the value of my props in a Nuxtjs app.

export default {
  props: {
    moved: {
      default: false,
      type: Boolean,
    }
  },
  data: function () {
    if (!this.moved){
        dataName: {
          fill: "value1"
        } 
    else dataName: {
          fill: "value2"
          } 
    return dataName
    }
  }
}

But I have an error message telling me that dataName is not defined. I don't know what I am doing wrong here...

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

0

You can make computed property instead:

Vue.component('Child', {
  template: `
    <div>
      {{ dataName }}
      <svg height="210" width="500">
        <polygon points="100,10 40,198 190,78 10,78 160,198" :fill="dataName.fill"/>
      </svg>
    </div>
  `,
  props: {
    moved: {
      default: false,
      type: Boolean,
    }
  },
  computed: {
    dataName() {
      let mov = {}
      this.moved ? mov.fill = 'blue' :  mov.fill = 'red'
      return mov
    }
  }
})

new Vue({
  el: '#demo',
  data() {
    return {
      moved: false
    }
  },
  methods: {
    changeMov() {
      this.moved = !this.moved
    }
  }
})

Vue.config.productionTip = false
Vue.config.devtools = false
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="demo">
  <button @click="changeMov">Change</button>
  <Child :moved="moved" />
</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