Home > Software design >  Vuejs props with a long path
Vuejs props with a long path

Time:05-09

I have a component with props like that:

 props: {
   data: Object
 },

data display: {{ data.a.b.c.d.title }}

I want to create a variable like: d = this.data.a.b.c.d.

data display: {{ d.title }}

What is the best practice to create this variable?

CodePudding user response:

Use a computed prop, like this...

props: {
  data: Object
},
computed: {
  d() {
    return this.data.a.b.c.d;
  }
},

<!-- in the markup -->
<p>{{ d.title }}</p>
  • Related