【发布时间】:2020-05-04 20:36:19
【问题描述】:
我正在尝试将对象推送到来自 axios 获取请求的响应中,但我总是收到“推送不是函数”错误
我正在尝试在 http 请求的 .then 块内推送
ps:我正在关注 vuejs 网站上的示例
var app = new Vue({
el: '#app',
data: {
message: 'Hello Vue!',
bitCoinValue: null
},
mounted() {
this.getBitcoinValue();
},
filters: {
currencydecimal(value) {
return value.toFixed(2);
}
},
methods: {
getBitcoinValue: function () {
axios.get('https://api.coindesk.com/v1/bpi/currentprice.json')
.then(response => {
this.bitCoinValue = response.data.bpi || [];
this.bitCoinValue.push({code: 'BRL', description: 'Reais', symbol: 'R$', rate_float: 25.50});
});
}
}
})
这是错误信息:
Uncaught (in promise) TypeError: this.bitCoinValue.push is not a function 在 site.js:21
【问题讨论】:
-
初始化你的
bitCoinValue为空array而不是null
标签: javascript vuejs2 axios