Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
AJAX调用异步返回的VUE.js问题值_Ajax_Vue.js - Fatal编程技术网

AJAX调用异步返回的VUE.js问题值

AJAX调用异步返回的VUE.js问题值,ajax,vue.js,Ajax,Vue.js,我对VUE有问题 我已经创建了一个管理类别网格的组件 源代码: Vue.componentProducts{ 模板:` [{{cards[0].fields.parent}}]] {{card.fields.category_name} `, 安装{ 这是fetchData }, 资料{ 返回{ 卡片:[], granParentId:null } }, 方法:{ 获取数据id{ 如果typeof id==“未定义”&&typeof this.cards.length>0{ id=this.ca

我对VUE有问题

我已经创建了一个管理类别网格的组件

源代码:

Vue.componentProducts{ 模板:` [{{cards[0].fields.parent}}]] {{card.fields.category_name} `, 安装{ 这是fetchData }, 资料{ 返回{ 卡片:[], granParentId:null } }, 方法:{ 获取数据id{ 如果typeof id==“未定义”&&typeof this.cards.length>0{ id=this.cards.fields[0]。父级 } 否则,如果typeof id='undefined'&&typeof this.cards.length==0{ id=null } axios.get'http://localhost:9002/get_subcategories“,{params:{id:id}” 。然后响应=>{ this.cards=response.data 返回响应.data } }, 获取数据2 id{ parent=this.getGranParent id 返回此.fetchData父级 /* var self=这个 父项=this.getGranParent id。然后响应=>{ 返回self.fetchData父级 } */ }, getGranParent id{ var self=这个 axios,快http://localhost:9002/get_granparent“,{params:{id:id}” 。然后响应=>{ self.granParentId=response.data 返回响应.data } } } } 遥控器模型是这样的

身份证 类别名称 形象 父类别可能为空

1;"Formaggi";"formaggi.jpg";
2;"Pecorini";"pecorini.jpg";1
3;"Caciotte";"caciotte.jpg";1
4;"Primosale";"primosale.jpg";1
5;"Grana";"grana.jpg";1
6;"Ortaggi";"ortaggi.jpg";
7;"Prodotti da forno";"pani.jpg";
8;"Olii";"olii.jpg";
9;"Carni";"carni.jpg";
10;"Salumi";"salumi.jpg";
11;"Salami";"salami.png";10
12;"Prosciutti";"prosciutti.jpg";10
13;"Salsicce";"salsicce.jpg";10
14;"Grana Padano";"grana_padano.jpg";5
15;"Parmiggiano Reggiano";"parmiggiano.jpg";5
正如您所看到的,op level categories元素没有指定值,最后一个字段为null。 当我选择一个具有回调fetchData id的类别时,我得到了所有将此id作为父类别的子类别。 对于子类别也可以这样做。 当我试图回到以前的水平时,问题出现了。 我已经找到了一种方法,即返回当前级别子类别的父级的父级id。 当我试图获取它时,我执行了一个对另一个远程AJAX调用的调用,该调用获取父对象的父对象。但是th调用异步返回值,当她返回时,调用方法fetchData2的返回就完成了

在源代码中,您可以在58和81之间的行中看到感兴趣的代码。

axios.get return Promise as async response,因此您必须正确处理此问题:

获取数据2 id{ this.getGranParent id.thenparent=>this.fetchData父级 }, getGranParent id{ 返回axios,获取'http://localhost:9002/get_granparent“,{params:{id:id}” 。然后响应=>{ this.granParentId=response.data 返回响应.data } }
Pastebin url已断开。无需导航到外部链接即可理解问题。问题中应提供最少的代码。也请看,请看:非常感谢,我意识到我做错了什么,但我无法确定如何兑现承诺。