我在 vue2 中使用 axios put 请求时遇到问题 以下代码用于保存更新表单。
有 2 个流程调用此方法。
- 您点击一个组织,window.location.hash 将更改为用户填写表单并点击保存的组织 ID
- 用户将转到网址中包含 window.location.hash 的组织页面 (#1 (#id)),用户填写表单并单击“保存”
代码:
/**
* Handle the update form.
*
* @param {array} selected
* @return {Promise}
*/
update(selected) {
this.$refs.updateForm.validate();
console.log('1');
return new Promise((resolve, reject) => {
console.log('2');
if (this.updateForm.valid) {
console.log('3');
this.$http
.put('organisation/' + selected[0].id, this.updateForm.values)
.then(() => {
console.log('10');
resolve();
})
.catch(error => {
console.log('NO');
console.log(error)
});
console.log('4');
}
});
},
结果: 如果情况 1 一切正常,console.log:
OrganisationResource.vue?2497:135 1
OrganisationResource.vue?2497:138 2
OrganisationResource.vue?2497:140 3
OrganisationResource.vue?2497:151 4
OrganisationResource.vue?2497:144 10
如果情况 2 不起作用,则未发出请求,console.log:
OrganisationResource.vue?2497:136 1
OrganisationResource.vue?2497:138 2
OrganisationResource.vue?2497:140 3
Also in case 2, a console.log in the axios request interceptor is not triggered. And when after flow 2, you start flow 1 without a page refresh, it works perfectly
我也不知道如何进一步调试它。
最佳答案
您应该检查 selected[0]
和 this.updateForm
是否已定义。否则访问它会抛出异常,因此 axios 的 then
和 catch
都不会被调用。
关于javascript - axios没有发出请求,没有结果,没有错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48887803/