[Vuejs]-How to do a if in a export default

0👍

Most likely you are importing it in another module using curly brackets. When default exporting, it should be imported without curly brackets.

Wrong:

import {something} from someModule

Right:

import something from someModule

0👍

You can do this to add inline optional properties to an object:

export default {
  ...(character !== 'Passé' ? {} : { steps: [<your steps array>] })
}

The ... is called a spread operator. It will expand the properties of the variable attached to it into the parent object (also works for arrays). In this case, we are adding either {} (nothing) or { steps: [] } based on your condition.

You can also do steps: character !== 'Passé' ? [] : [ <steps array> ]
This will make it so that steps will always be defined on your object as an array.

Both of these will work.

Leave a comment