data(){
return {
tables:[] 。
}
},
mounted(){
this.getData()
},
methods:{
getData(){
var subscription = web3.eth.subscribe('logs'/span>, {
address: '0x123456.'。
topics: ['0x12345...']
}, function(error, result){
if (! error)
console.log(結果)。
})
.on("data"/span>, function(log){
// this.tables回傳錯誤資訊typeError。傳播非可迭代實體的無效嘗試。為了實作可迭代,非陣列物件必須有一個[Symbol.iterator]()方法。
this.tables = [...log] 。
})
}
}
在vue JS中,我無法訪問填充this.tables的資料,有什么其他方法可以做到這一點?
uj5u.com熱心網友回復:
'this.tables'在這里是指回呼函式的表,回呼中的'this'并不針對vue資料。
嘗試 this.getData(this.tables) in mounted()。
和方法中的getData(tables),
那么回呼應該是
function(log, tables){ tables = [...log]}
uj5u.com熱心網友回復:
好吧,我現在想明白了,所以解決方案是
。
const self = this
var subscription = web3.eth.subscribe('logs', {
address: '0x123456.'。
topics: ['0x12345...']
}, function(error, result){
if (! error)
console.log(結果)。
})
.on("data"/span>, function(log){
self.tables.push(log)
})
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/327371.html
標籤:
