How can you shorten validation in Vue?

How can you shorten validation in Vue?

<template 
  v-if="editedItem.arrayImages4 && editedItem.arrayImages4.length > 0"
></template>

Upvotes: 1

Views: 50

Answers (1)

kissu
kissu

Reputation: 46761

Nothing too fancy that you can do here, maybe use computed + some optional chaining like this (you can't do this in the template unfortunately)

<template v-if="doItemContainImages"></template>
computed: {
  doItemContainImages() {
    return editedItem?.arrayImages4?.length
  },
},

Upvotes: 4

Related Questions