带有 axios 的 Vue 需要 5 到 7 秒才能使用小数据进行 api 调用

Vue with axios need 5 to 7 seconds for api call with small data

提问人:beli3ver 提问时间:5/23/2022 更新时间:5/23/2022 访问量:363

问:

日安

我的 VUE 应用程序存在很大问题,即我的 API 调用非常非常慢。

我有一个 Laravel 后端,可以及时提供数据,并通过域 https://api.example.com 做出相应的响应。

但是,在我的仪表板中,我进行了三个 API 调用,加载内容需要 5 到 8 秒:enter image description here

结果,用户大量抱怨加载时间。 在代码中,我目前按如下方式调用调用:

  async mounted() {
    this.personalDeletegatesId = userInfo.user.delegatesid
    this.getTasks()
    this.getAddresses()
    this.getRequestTypes()
  },

每个函数都是作为异步方法创建的。 无论是在生产中还是在本地,应用速度都很快。

    getAddresses: async function () {
      this.$http.get('/addresses/delegates/' + userInfo.user.delegatesid)
          .then(function (response) {
            this.items = uniqueElementsBy(response.data[0], (a, b) => a.id == b.id)
            this.itemsnotasks = uniqueElementsBy(response.data[1], (a, b) => a.id == b.id)
            this.itemsfav = uniqueElementsBy(response.data[2], (a, b) => a.id == b.id)
            this.getCounts()

            }.bind(this))
    },
    getTasks: async function () {
      this.$http.get('/salestasks/delegates/' + userInfo.user.delegatesid)
          .then(function (response) {
            this.itemsTasks = uniqueElementsBy(response.data, (a, b) => a.salestasks_id == b.salestasks_id)
          }.bind(this))
    },
vue.js axios vuetify.js

评论

0赞 kissu 5/23/2022
你能同时运行所有这些吗?您是否使用邮递员或类似人员调试了响应时间?因为您的后端总体上回答速度可能很慢。也使用相同的 URL(我猜是生产?
0赞 beli3ver 5/23/2022
后端速度很快,我可以在浏览器中打开 api url,50 毫秒后立即出现 JSON 响应。这一定是前端的问题。
0赞 kissu 5/23/2022
嗯,尝试复制相同的条件。或者使用 axios 调用调用一个端点。它可能并不总是很快,或者某些东西有副作用。邮递员仍然是一个有效的假设。此外,中间件、线程阻塞操作等......可能会导致客户端操作出现一些整体滞后。
0赞 The Guardian 5/23/2022
列表中有多少个项目?数据的结构是什么?
0赞 beli3ver 5/23/2022
getAddresses => 100 到 150 和 getTasks => 50 到 60,数据在 json 数组中

答: 暂无答案