【发布时间】:2019-07-29 05:53:07
【问题描述】:
我正在我的 vue.xml 中创建一个动态数组。此数组正在从 JSON 数组的脚本中填充,但未在模板中更新。在模板中它返回空白数组。这是我的代码:
<template>
<div>
{{users}} <!-- this is returning blank -->
</div>
</template>
<script>
export default {
data(){
return {
users: []
}
},
created(){
this.fetchUsers();
},
methods:{
fetchUsers(){
fetch('api/single')
.then(res => res.json())
.then(res => {
this.users= res.data;
console.log(this.users); //this is showing the data
})
.catch(err => console.log(err));
}
}
};
</script>
【问题讨论】:
标签: javascript arrays vue.js