【发布时间】:2021-11-15 03:30:13
【问题描述】:
data(){
return {
tables:[]
}
},
mounted(){
this.getData()
},
methods:{
getData(){
var subscription = web3.eth.subscribe('logs', {
address: '0x123456..',
topics: ['0x12345...']
}, function(error, result){
if (!error)
console.log(result);
})
.on("data", function(log){
// this.tables return the error message typeError: Invalid attempt to spread non-iterable instance.In order to be iterable, non-array objects must have a [Symbol.iterator]() method
this.tables = [...log]
})
}
}
在 vue JS 中我无法访问填充 this.tables 以获取数据还有什么其他方法可以做到这一点?
【问题讨论】:
-
log变量在.on("data", function(log){中是什么样的?我认为它不能用像[..log]developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/… 这样的传播运算符传播 -
日志只是一个返回的数据,我没有问题,但问题是“this.tables”似乎我无法通过那里,所以即使我做了 console.log( this.tables) 它返回 undefined
-
log是什么数据?是字符串还是数字? -
对象数据类型
-
如果它是一个对象,我认为你不能将一个对象传播到一个数组中。
标签: javascript vue.js web3js