javascript - axios没有发出请求,没有结果,没有错误

标签 javascript http vue.js vuejs2 axios

我在 vue2 中使用 axios put 请求时遇到问题 以下代码用于保存更新表单。

有 2 个流程调用此方法。

  1. 您点击一个组织,window.location.hash 将更改为用户填写表单并点击保存的组织 ID
  2. 用户将转到网址中包含 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 的 thencatch 都不会被调用。

关于javascript - axios没有发出请求,没有结果,没有错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48887803/

相关文章:

javascript - 如何合并实例中的模块?

javascript - 如何保护 JavaScript/Ajax 客户端 [apigee] 中使用的 API 的安全?

angularjs - $http.post() 方法实际上是发送一个 GET

http - 带有 https/ssl 页面的纯 http 图像

javascript - 带有jquery点击事件的嵌套div的索引?

Javascript 循环和值

C# 从未知格式下载图像

javascript - 在 vue.js 应用程序中使用浏览器后退/前进按钮

vue.js - 类星体 : Is there any way to get the value typed into a QSelect with use-input before it gets removed on blur?

javascript - 使用 VueJS 和 Quasar 将焦点更改为 "Enter"键上的下一个输入字段