我在 vue 中使用surveyjs,并试图var json
从我的 API 中获取我的问题。
使用 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 响应的正确方法是什么?