Answer the question
In order to leave comments, you need to log in
How correct is it to overwrite the property?
There is a component whose behavior (conditional rendering) can be determined by different things.
They have their own priority. Props of the path, Props from the parent, the state of some getter in state.
How correct is it to do this:
mounted () {
if (prop) {
this.x = 'a'
}
if (route) {
this.x = 'b'
}
if (state) {
this.x = 'c'
}
}
Answer the question
In order to leave comments, you need to log in
There are too many if's and assignments. You can add the data to an array and look for a suitable value in it:
const data = [
[ state, 'c' ],
[ route, 'b' ],
[ prop, 'a' ],
].find(n => n[0]);
if (data) {
this.x = data[1];
}
x
a computed property.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question