sách gpt4 ăn đã đi

javascript - 将 surveyjs 结果发送到 API

In lại 作者:搜寻专家 更新时间:2023-10-30 22:21:08 28 4
mua khóa gpt4 giày nike

我正在尝试将 surveyjs 结果发送到我的 API。

在 mounted() 中,我使用 vue-resource 发出一个 LẤY 请求,从我的 DB 中获取问题,然后设置 surveyjs。为了发送结果,我尝试在 surveyJS onComplete 函数中使用 this.$http.post,但我得到了 Cannot read property 'post' of undefined 。此外,我尝试监视 kết quả 变量,但没有成功。

gắn kết() {
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(phản hồi);
UIkit.notification({
message: "Success",
pos: "top-center",
status: "success"
});
})
.catch(error => {
console.log(lỗi);
UIkit.notification({
message: "Erro",
pos: "top-center",
status: "danger"
});
});
});
})
.catch(error => {
console.log(lỗi);
UIkit.notification({
message: "Error",
pos: "top-center",
status: "danger"
});
});
}

câu trả lời hay nhất

要访问 onComplete.add() 参数中的 cái này,您可以用箭头函数替换常规函数:

this.survey.onComplete.add(survey => {
this.result = survey.data;
/* rest of your code... */
})

另一种方法是将 cái này 放入一个变量中,该变量可用于访问外部 cái này:

const that = this;
this.survey.onComplete.add(function(survey) {
that.result = survey.data;
/* rest of your code... */
})

阅读更多关于 cái này 的信息.

它的要点是在函数内部,函数的 cái này 覆盖组件的 cái này ,除非它是箭头函数,它有意没有 cái này 因此外部可用。

关于javascript - 将 surveyjs 结果发送到 API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56331253/

28 4 0
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress