Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

115
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!