Reputation: 5255
I have a VueComponent for which I need to pass a value "A". the problem is the value A can be passed VueRouter parameter or via the template interpolation. What is the best way to set a property data via both options?
e.g.
<component :property="value"></component>
if I navigate to
/component/8/edit
mounted() {
this.property = this._route.params.id
}
Upvotes: 0
Views: 912
Reputation: 73639
You have to figure out to which parameter you want to give priority, If you want to give priority to route
param, you can do following:
mounted() {
this.property = this.$route.params.id ? this.$route.params.id : this.property
}
If you want to give priority to props being passed, you can write:
mounted() {
this.property = this.property ? this.property : this.$route.params.id
}
Upvotes: 1