Global Variables (or previous answers) via QuestionModel?
liamb13 opened this issue · 1 comments
liamb13 commented
This may already be possible and I'm just having a mind blank.
Using the Questionnaire example, how could I keep 'first_name' to reuse it in taglines and titles of multiple other questions? I know it can be done within components but how about in a questions data array?
I tried with the following:
export default {
data() {
return {
name_label: "",
questions: [
new QuestionModel({
id: "first_name",
title: `What is your name?`,
...
}),
new QuestionModel({
id: "email",
title: `Nice to meet you ${this.name_label}! What is your email?`,
...
}),
],
}
},
methods: {
onQuestionAnswered(question) {
if (question.id === "first_name" && question.answer !== null) {
this.name_label = question.answer;
}
},
},
};
Instead ended up using, which only covers 1 question and isn't multiple language friendly:
onQuestionAnswered(question) {
console.log(question);
if (question.id === "first_name" && question.answer !== null) {
this.questions[1].tagline = `Nice to meet you ${question.answer}. What is your email?`;
}
},