0

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)
}
5
  • Where is the getFittingAnswer? Is it a method from the parent component? Commented Jun 15, 2017 at 14:13
  • Yes it is - it works perfectly fine but kind of has to be "retriggered". Commented Jun 15, 2017 at 14:13
  • I'm not sure I understand your case well. Can you provide a more complete code sample? Commented Jun 15, 2017 at 14:16
  • @Cobaltway Check the update. Commented Jun 15, 2017 at 14:20
  • Sorry I still do not get what the problem is. Is it a reactivity problem? What do you mean by "retriggered"? Maybe you can share the two components code (parent and child), possibly on a fiddle or code snippet? Commented Jun 15, 2017 at 14:25

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

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.