变量未在vue js中更新,显示变量未定义

时间:2019-06-03 05:26:49

标签: javascript html vue.js vuejs2

我正在尝试在html中绑定totalQuestions变量的更新值。但它显示以下错误。谁能告诉我我做错了什么地方。

enter image description here

HTML

<label><span class="red-text">Question No: </span><span>1 out of {{totalQuestions}}</span>/</label>

变量:

date() {
        return {
            examKey: '',
            questionsIds: '',
            duration: 0,
            questionList: [],
            totalQuestions: ''
        }
    },

方法

methods: {
    loadQuestionSet: function() {
            this.examKey = this.$route.params.key;
            this.$http.get(baseUrl.BASE_URL + 'question-set/key/' + this.examKey).then(
                (resp) => {
                    this.duration = resp.data.duration;
                    this.questionsIds = resp.data.questionIds;
                    this.loadQuestions();
                },
                (err) => {
                    this.$router.push("/exam");
                }
            );
        },

        loadQuestions: function() {
            this.$http.post(baseUrl.BASE_URL + 'question/exam/questions', this.questionsIds).then(
                (resp) => {
                    this.questionList = resp.data;
                    this.totalQuestions = this.questionList.length
                },
                (err) => {
                    console.log(err);
                }
            );
        }
},
beforeMount: function() {
        this.loadQuestionSet();
    }

1 个答案:

答案 0 :(得分:4)

您有错字:date()应该是data()

相关问题