作为一个对API开发和web开发非常陌生的人,我试图了解在我的VueJS应用程序中进行递归API调用的最佳实践是什么。
数据:
分类
ID | ParentID | Name
============================
1 | NULL | Car
2 | NULL | Bikes
3 | 1 | Sports Car
4 | 2 | Sport Bike
5 | 3 | SuperBike
我正在调用一个API来检索这些cat,并创建一个由ParentID为NULL的那些人开始的下拉项。
<b-dropdown v-for="item in categories" :key="item.id" v-bind:text="item.name" id="ddown1" class="m-md-1">
export default {
name: "app",
components: {
Top,
Side,
Center
},
data() {
return {
msg: "USAFE",
categories:[]
}
},
created: function()
{
this.fetchItems();
},
methods: {
fetchItems()
{
let uri = 'http://localhost:8180/unv-api/categorie/search/rsql?query=ParentId==NULL';
this.axios.get(uri).then((response) => {
this.categories = response.data._embedded.categories;
});
}
}
};
现在我想使用ParentId属性添加子下拉列表和child。
实现这一目标的最佳实践是什么?