javascript - Axios GET 没有显示所有数据。我需要打第二个电话才能接他们
问题描述
我有一个带有表格的 vue 组件
<v-client-table
ref="table"
:data="artists"
:columns="columnsDatatable"
:options="optionsDatatable"
@row-click="rowDetail"
>
<!-- ID -->
<template v-slot:id="props">
<small>#{{ props.row.id }}</small>
</template>
<!-- Fullname -->
<template v-slot:fullname="props">
{{ props.row.lastname }} {{ props.row.name }}
</template>
</v-client-table>
它从在 mount() 期间调用的 Vuex 突变中获取数据
mounted() {
this.fetchArtists();
}
当我将数据存储到 dBase 并更新 vuex 数组艺术家时,表格只显示了其中的一部分。为了解决我必须重新加载页面的问题,让组件让 axios 再次获取并最终看到我需要的所有数据。我想知道为什么会发生任何想法?
这里是 fetch 动作
async fetchArtists({commit}) {
axios.get(config.backend + "/artists")
.then(res => {
commit("SET_ARTISTS", res.data.data);
console.log("mounted", res.data.data);
})
.catch();
},
这里是 saveArtist 动作
async saveArtist({ state, dispatch, commit }, [artist, contacts, address, certificates]) {
// Save
await axios.post(config.backend + "/artists", artist)
.then(res => {
let id = res.data.data.id;
contacts.contactable_id = address.addressable_id = certificates.certificatable_id = id;
contacts.contactable_type = address.addressable_type = certificates.certificatable_type = 'App\\Models\\Artist';
if (!!contacts.first_email) {
axios.post(config.backend + "/contacts", contacts)
.then(res => console.log(res))
.catch(err => console.log(err));
}
if (!!address.address) {
axios.post(config.backend + "/addresses", address)
.then(res => console.log(res))
.catch(err => console.log(err));
}
let fullArtist = artist;
fullArtist.contact = contacts;
fullArtist.map = address;
commit('PUSH_TO_ARTISTS', fullArtist);
commit('common/SET_ALERT_TITLE', 'CREATED', { root: true });
commit('common/SET_ALERT_MESSAGE', 'Artist has been created!', { root: true });
commit('common/SET_ALERT_COLOR', 'success', { root: true });
})
.catch(err => console.log(err));
},
解决方案
推荐阅读
- javascript - 返回混乱的方法 array.map 和 array.filter
- python - Google Cloud Function 的 HTTP 触发器问题
- java - 有没有办法重新开始整个代码?
- image - Navision SSRS IIF 在为 TRUE 时执行 Else?
- angular - Angular http:通过链接它们来防止调用多个请求
- pointers - 在 Firefox 中的另一个元素捕获指针事件时触发 DIV 上的单击事件
- flutter - Flutter 中的 Firestore 查询快照是否为空?
- python - 使用链表实现哈希映射?
- python - 在 Odoo 13 的 one2many 关系中显示非活动记录
- javascript - 如何在模块中以编程方式确定是否通过脚本 src 加载了 javascript 模块(未导入)