我正在尝试将调查结果发送到我的 API。
在mounted() 中,我使用 提出GET
请求vue-resource
,从我的dB 中获取问题,然后设置surveyjs。为了发送结果,我尝试this.$http.post
在surveyJSonComplete
函数中使用 , 但我得到了Cannot read property 'post' of undefined
. 另外,我试图监视result
变量,但它不起作用。
mounted() {
this.$http
.get("myAPI")
.then(res => res.json())
.then(questions => {
this.questions = questions;
this.survey = new SurveyVue.Model(this.questions.pesquisa);
this.survey.locale = "pt";
this.survey.onComplete.add(function(survey) {
this.result = survey.data;
this.$http
.post(
`myAPI`,
this.result,
{ headers: { "Content-Type": "application/json" } }
)
.then(response => {
console.log(response);
UIkit.notification({
message: "Success",
pos: "top-center",
status: "success"
});
})
.catch(error => {
console.log(error);
UIkit.notification({
message: "Erro",
pos: "top-center",
status: "danger"
});
});
});
})
.catch(error => {
console.log(error);
UIkit.notification({
message: "Error",
pos: "top-center",
status: "danger"
});
});
}