How to set as default value a variable in a prop in Vue.Js?

Viewed 27

I have a question. I need to set a prop with a default value that is obtained from a getter.

props: {
    userID: {
      type: String,
      default: ''
    }
  }

The value that I want to set as default value is obtained with:

computed: {
    ...mapGetters('Auth', ['getId']),

}

How can I make the prop UserID have as default value the getId that is obtained from the mapGetter?

1 Answers

You can use computed property for setting the default value.

computed: {
  userIdComp() {
    return this.userID ?? this.$store.getters['Auth/getId'];
  }
}

And use userIdComp instead of userID

Related