从 db 获取 surveyjs 问题
Get surveyjs questions from db
我在 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 响应的正确方法是什么?
我想你可以使用这样的东西:
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。您现在应该可以访问您的调查数据了。
我在 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 响应的正确方法是什么?
我想你可以使用这样的东西:
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。您现在应该可以访问您的调查数据了。