0

Is it possible to decide which property in object is going to be defined depending on condition? For example:

props="{
   'prop1': {label: 'Prop1'},
   hasProp2 ? '(prop2': {label: 'Prop2'}) : ('prop3': {label: 'Prop3'}),
   'prop4': {label: 'Prop4'}
}"

And let's say hasProp2 is computed property with a function which returns true or false. How can I use ternary operator or basic if statement inside object or is it even possible?

juniorjunior
  • 69
  • 1
  • 11

1 Answers1

1

You could test it realy simple

var a = 1;
var b = 2;

var c = {
    prop_a: a = 1 ? 'YES' : 'NO'
}

console.log(c);

As you can see it it possible. Vue is reactive, and will work too.

Ernst Reidinga
  • 203
  • 2
  • 13