Answer the question
In order to leave comments, you need to log in
How to call a method when data changes?
<ul>
<li v-for="user in users">{{ showName(user) }}<li>
</ul>
...
methods: {
showName(user) {
if (user.name && !user.lastname) {
return 'Some value';
} else if (...) {
...
} else {
return user.name;
}
}
}
...
Answer the question
In order to leave comments, you need to log in
Should change, add key:
<li v-for="user in users" :key="user.id">{{ showName(user) }}<li>
try computed
computed: {
showName(user) {
if (user.name && !user.lastname) {
return 'Some value';
} else if (...) {
...
} else {
return user.name;
}
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question