[英]How to set as default value a variable in a prop in Vue.Js?
I have a question.我有个问题。 I need to set a prop with a default value that is obtained from a getter.
我需要使用从 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?如何使道具
UserID
具有从 mapGetter 获得的getId
作为默认值?
You can use computed
property for setting the default value.您可以使用
computed
属性来设置默认值。
computed: {
userIdComp() {
return this.userID ?? this.$store.getters['Auth/getId'];
}
}
And use userIdComp
instead of userID
并使用
userIdComp
而不是userID
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.