【发布时间】:2019-08-25 00:59:23
【问题描述】:
我在 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 响应的正确方法是什么?
【问题讨论】: