Java axios速度不够快,无法加载数据

Java axios速度不够快,无法加载数据,java,vue.js,vuejs2,axios,Java,Vue.js,Vuejs2,Axios,我一直在尝试使用axios使用Vue加载数据,但出现了未定义的错误。我很确定我的代码没有问题,因为它与其他人一起工作。我认为问题在于页面是在axios有机会获取数据之前呈现的 async editGoods(oldGoods) { oldGoods.property1 = await this.$http.loadData("/item/someporperty/" + oldGoods.id); oldGoods.propert

我一直在尝试使用axios使用Vue加载数据,但出现了未定义的错误。我很确定我的代码没有问题,因为它与其他人一起工作。我认为问题在于页面是在axios有机会获取数据之前呈现的

 async editGoods(oldGoods) {
                oldGoods.property1 = await this.$http.loadData("/item/someporperty/" + oldGoods.id);
                oldGoods.property2 = await this.$http.loadData("/item/otherproperties/list?id=" + oldGoods.id);
                this.isEdit = true;
                this.show = true;
                this.oldGoods = oldGoods;
            }
下面是我的axios配置

import Vue from 'vue'
import axios from 'axios'
import config from './config'

axios.defaults.baseURL = config.api; 
axios.defaults.timeout = 2000; 

axios.loadData = async function (url) {
   const resp = await axios.get(url);
  return resp.data;
}

 Vue.prototype.$http = axios;
这是我一直收到的错误消息:

vue.esm.js?efeb:1741 TypeError: Cannot read property 'length' of undefined
    at eval (eval at ./node_modules/vue-loader/lib/template-compiler/index.js? 
{"id":"data-v-c02e22a2","hasScoped":true,"transformToRequire":{"video": 
["src","poster"],"source":"src","img":"src","image":"xlink:href"},"buble": 
{"transforms":{}}}!./node_modules/vue-loader/lib/selector.js? 
type=template&index=0!./src/pages/item/GoodsForm.vue (4.js:276), 
<anonymous>:332:47)
    at Proxy.renderList (vue.esm.js?efeb:3705)
    at Proxy.render (eval at ./node_modules/vue-loader/lib/template- 
compiler/index.js?{"id":"data-v- 
c02e22a2","hasScoped":true,"transformToRequire":{"video": 
["src","poster"],"source":"src","img":"src","image":"xlink:href"},"buble": 
{"transforms":{}}}!./node_modules/vue-loader/lib/selector.js? 
type=template&index=0!./src/pages/item/GoodsForm.vue (4.js:276), 
<anonymous>:320:23)
     at VueComponent.Vue._render (vue.esm.js?efeb:4544)
     at VueComponent.updateComponent (vue.esm.js?efeb:2788)
     at Watcher.get (vue.esm.js?efeb:3142)
     at Watcher.run (vue.esm.js?efeb:3219)
     at flushSchedulerQueue (vue.esm.js?efeb:2981)
     at Array.eval (vue.esm.js?efeb:1837)
     at MessagePort.flushCallbacks (vue.esm.js?efeb:1758)
vue.esm.js?efeb:1741 TypeError:无法读取未定义的
在eval(eval at./node_modules/vue loader/lib/template compiler/index.js?
{“id”:“data-v-c02e22a2”,“hasScoped”:true,“transformToRequire”:{“video”:
[“src”,“poster”],“source”:“src”,“img”:“src”,“image”:“xlink:href”},“buble”:
{“transforms”:{}}..//node_modules/vue loader/lib/selector.js?
type=template&index=0!。/src/pages/item/GoodsForm.vue(4.js:276),
并且.GoodsForm.vue是正在呈现的表单


已经尝试了好几天了,有人知道如何处理吗?

如果您想在axios获取数据后立即显示数据,一种方法是根据数据模型的值设置组件的If条件。就像这一种

在您的数据中,您可以像新数据一样声明,比如说是加载

data() {
   return {
      is_loaded:false
   }
}
现在,在您的组件中,您应该应用一个条件,以防止在axios尚未完成抓取时加载组件

<template>
     <div v-if="is_loaded">
         ...
         ...
     </div>
</template>
 axios.get('api endpoint', {})
      .then(({data}) => {
       ...
       ...
      this.is_loaded = true
 );

注意:当您已经通过响应完成数据模型的初始化时,您必须将其设置为真。

如果您想在axios获取数据后立即显示数据,一种方法是根据数据模型的值为组件设置If条件。如本例所示

在您的数据中,您可以像新数据一样声明,比如说是加载

data() {
   return {
      is_loaded:false
   }
}
现在,在您的组件中,您应该应用一个条件,以防止在axios尚未完成抓取时加载组件

<template>
     <div v-if="is_loaded">
         ...
         ...
     </div>
</template>
 axios.get('api endpoint', {})
      .then(({data}) => {
       ...
       ...
      this.is_loaded = true
 );

注意:当您已经通过响应完成数据模型的初始化时,您必须将其设置为真。

您在哪里使用了“长度”?在v-for中?您可以显示您在哪里使用“显示”的代码吗?在v-for中?您可以显示您在哪里使用“显示”的代码吗非常感谢您的详细回答,我将尝试一下。我在表格中定义了几个长度(已附上完整代码的链接),无法判断它所指的是哪一个。我不确定这里的问题是什么。错误仍然存在,但页面被呈现,这意味着在将数据加载到GoodsForm后,is_loaded将更改为True。这意味着这可能不是因为axios加载数据太慢。但我仍然无法确定是什么原因代码真的有问题。非常感谢你的详细回答,我会尝试一下。我在表格中定义了几个长度(附上了完整代码的链接),无法判断它所指的是哪一个。我不确定这里的问题是什么。错误仍然存在,但页面被呈现,这意味着在将数据加载到GoodsForm后,is_loaded将更改为True。这意味着这可能不是因为axios加载数据太慢。但我仍然无法确定是什么原因代码真的错了。