【发布时间】:2017-06-25 01:12:26
【问题描述】:
我正在从 reddit API 获取 cmets 并尝试使用 $set 更新数组以便它可以更新视图,但我收到此错误:
Uncaught (in promise) TypeError: $set is not a function
虚拟机组件:
export default {
name: 'top-header',
components: {
Comment
},
data () {
return {
username: '',
comments: []
}
},
methods: {
fetchData: function(username){
var vm = this;
this.$http.get(`https://www.reddit.com/user/${username}/comments.json?jsonp=`)
.then(function(response){
response.body.data.children.forEach(function(item, idx){
vm.comments.$set(idx, item);
});
});
}
}
}
【问题讨论】:
标签: javascript vue.js