从db获取surveyjs问题

问题描述 投票:0回答:1

我在vue中使用surveyjs,我正在尝试从我的API获取var json问题。

使用vue-resource,我向API发出GET请求,并将响应保存在questions中并将其放在var json

export default {
    components: {
           Survey
    },
    data(){
           this.$http.get('api')
           .then(res => res.json())
           .then(questions => {
               this.questions = questions;
           });
           var json = this.questions;
           var model = new SurveyVue.Model(json);
           return {
               survey: model,
               questions:''
           }
    }
}

使用console.log(json),我得到undefined。那么,在这种情况下访问API响应的正确方法是什么?

vue.js surveyjs
1个回答
1
投票

我想你可以使用这样的东西:

export default {
    components: {
           Survey
    },
    data() {
        return {
            survey: {},
            questions: ''
        }
    },
    mounted() {
        let self = this;
        this.$http.get('api')
           .then(questions => {
               self.questions = questions;
           });
        this.survey = new SurveyVue.Model(this.questions);
    }
}

您可以了解有关mounted方法here的更多信息。您现在应该能够访问您的调查数据。

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.