0

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
}

1 Answer 1

1

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 
}
Sign up to request clarification or add additional context in comments.

2 Comments

Slight off topic but related can a "data" property be a function when reference in the template syntax? i.e. data{ return { property(){ return this.otherProperty } } } or should it be left to computed because I want to do what you said and be able to override as needed
left a message for you in the chat

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.