【发布时间】:2020-08-27 15:34:43
【问题描述】:
我正在制作一个 vue 历史测验应用程序,我的问题是从 API 中检索出来的。我想在 ResultScreen 视图中显示问题、正确答案和用户的答案。我采取的方法是将问题推入一个数组并 $emit 它。我可以看到它存储在我的 vue 工具中,但由于某种原因,它没有显示在我想要显示的组件中,因此没有显示在 resultScreeen 中。
currentQuestion 是一个包含问题和答案的对象。
[发出数组的代码。]
storeQuestion: function (value) {
value = this.submitData.questionArray1
this.$emit('storeData', value)
console.log(value, 'my pants are on fire')
}
shows vue tools at it has been stored.
[我要投影的组件和不会显示问题的功能。]
<template>
<div>
<QuizQuestion
v-if="questions.length"
:currentQuestion="questions[index]"
@storeData="storeQuestion"
/>
<p v-if="questions">{{ questions }}</p>
<p v-else=""> loading.....</p>
</div>
</template>
<script>
// import { mapGetters } from 'vuex'
import QuizQuestion from '@/components/QuizQuestion.vue'
// se på gameplay hvor vi returner numcorrect, numtotal og numpoints, vi må se på hvordan vi kan importere verde
export default {
name: 'GameOver',
components: {
QuizQuestion
},
data () {
return {
questions: ''
}
},
methods: {
storeQuestion: function (value) {
this.questions = value
alert(value)
}
}
}
</script>
this.submitData.questionArray1.push(this.currentQuestion.question)
【问题讨论】:
-
与其链接到将来可能不存在的外部图像,不如复制粘贴到您的问题中。 ??????????
-
好的抱歉,先在这里发帖
标签: vue.js eventemitter emit