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)
}
您可以为更改时间创建全局事件总线,请调用此方法并侦听此方法并更新答案Vue.js全局事件总线
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.