gpt4 book ai didi

javascript - 无法在vue.js中执行for循环

转载 作者:行者123 更新时间:2023-12-03 08:56:07 24 4
gpt4 key购买 nike

我对 vue 很陌生。我正在尝试执行一个简单的 for 循环,但由于某种原因它不起作用。任何帮助将不胜感激。我的代码:

var Vue = require('vue');
Vue.use(require('vue-resource'));
Vue.http.headers.common['X-CSRF-TOKEN'] = document.querySelector('#token').getAttribute('value');
new Vue({

el: '#adresponse',

ready: function() {
this.fetchMessages();
},

data: {
classified_bids: {},
accept_qty: {},
submitted: false
},

methods: {
fetchMessages: function () {
this.$http.get('/api/getbids')
.success(function (bids) {
this.classified_bids = bids;
for (i = 0; i < this.classified_bids.length; i++) {
this.accept_qty[i] = 0;
}
});
}
}
});

最佳答案

通过像这样更改 for 循环,这有效:

el: '#adresponse',

ready: function() {
this.fetchMessages();
},

data: {
classified_bids: {},
accept_qty: {},
submitted: false
},

methods: {
fetchMessages: function () {
this.$http.get('/api/getbids')
.success(function (bids) {
this.classified_bids = bids;
for (var key in this.classified_bids) {
this.accept_qty[key] = 0;
}
});
}
}

});

关于javascript - 无法在vue.js中执行for循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32496794/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com