【发布时间】:2019-04-30 15:02:48
【问题描述】:
我在 vue.js 中构建了一个页面,其中调用了一个 API(使用 axios)获取一个大型 json 对象(1k+)。
在处理这个对象时,我想向用户展示操作的进度 - 没有什么比进度条更花哨的了,只是一个简单的“从 Y 处理 X”。
我找到了如何在纯 JS 的 jquery 中执行此操作的示例,但我可以让它在 vue 中工作。
感谢任何帮助。
这是我的骨架代码:
<div>Processed {{processed.current}} of {{processed.total}} records</div>
<script>
data() {
return {
progress:{
current:0,
total: 0
},
records: [],
};
},
mounted() {
this.getRecords();
},
methods: {
getRecords(){
axios({
method: "GET",
url: process.env.VUE_APP_REPORTING_API + "/Reports/orders",
headers: {
"content-type": "application/json",
Authorization: this.$cookie.get("wwa_token")
}
}).then(
result => {
this.progress.total = result.data.length;
//and here where the loop should happen, something like this
//obviously the below won't work :)
result.data.forEach(function(item) {
this.records.push(item);
this.progress.current++;
}
},
error => {
}
);
}
}
</script>
【问题讨论】:
-
运行代码时遇到什么样的错误?
标签: vuejs2