sandrooco
sandrooco

Reputation: 8716

vue.js: Trigger binding update manually

I have a template calling a different component:

<question-container v-for="(question, index) in questions" :question="question" :answer="getFittingAnswer(question)"></question-container>

How can I update the :answer manually from the outer component? As :answer is dynamic based on data on a server and session data, in need the getFittingAnswer function.

Update: This is the getFittingAnswer component method.

getFittingAnswer(question) {
    return this[`part${question.part}answers`].find(a => a.questionId == question.Id)
}

Upvotes: 0

Views: 1643

Answers (2)

sandrooco
sandrooco

Reputation: 8716

As the getFittingAnswer method returns an object from my component data I simplified the template:

<question-container v-for="(question, index) in questions" :question="question" :value="part1answers.find(a => a.questionId == question.Id)"></question-container>

Using this directly, the data will always be up-to-date.

Upvotes: 0

Murad Sofiyev
Murad Sofiyev

Reputation: 791

You can create global event bus for change time call this methods and listen this method and update answer Vue.js global event bus

Upvotes: 1

Related Questions